From 9c6a8878d9c82cf223ecc0832528fcf266b8b71d Mon Sep 17 00:00:00 2001 From: "Tyson J. Hayes" Date: Mon, 20 Oct 2014 23:04:19 -0700 Subject: [PATCH 1/2] Modifying Enable-DscEventLog to be exportable --- Tooling/cDscDiagnostics/cDscDiagnostics.psm1 | 67 +++++++++++--------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 b/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 index f3406a2..0b3e06b 100644 --- a/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 +++ b/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 @@ -592,59 +592,66 @@ function Get-AllGroupedDscEvents } - <# -.SYNOPSIS -Sets any DSC Event log (Operational, analytic, debug ) +function Enable-DscEventLog +{ + <# + .SYNOPSIS + Sets any DSC Event log (Operational, analytic, debug ) -.DESCRIPTION -This cmdlet will set a DSC log when run with Enable-DscEventLog . + .DESCRIPTION + This cmdlet will set a DSC log when run with Enable-DscEventLog . -.PARAMETER Channel -Name of the channel of the event log to be set. + .PARAMETER Channel + Name of the channel of the event log to be set. -.EXAMPLE -C:\PS> Enable-DscEventLog "Analytic" -C:\PS> Enable-DscEventLog -Channel "Debug" -#> - function Enable-DscEventLog - { - param( - $Channel="Analytic" + .EXAMPLE + C:\PS> Enable-DscEventLog "Analytic" + C:\PS> Enable-DscEventLog -Channel "Debug" + #> + + [CmdletBinding()] + param + ( + [ValidateSet("Debug", "Analytic", "Operational")] + [string] $Channel = "Analytic", + + [string] $ComputerName = $env:ComputerName, + [PSCredential] $Credential ) - $LogName="Microsoft-Windows-Dsc" + $LogName = "Microsoft-Windows-Dsc" + + $eventLogFullName = "$LogName/$Channel" - $eventLogFullName="$LogName/$Channel" try { - Log -Verbose "Enabling the log $eventLogFullName" - if($Script:ThisComputerName -eq $env:COMPUTERNAME) + Write-Verbose "Enabling the log $eventLogFullName" + if($ComputerName -eq $env:COMPUTERNAME) { - wevtutil set-log $eventLogFullName /e:true /q:true + wevtutil set-log $eventLogFullName /e:true /q:true } else { + # For any other computer, invoke command. + $scriptTosetChannel = [Scriptblock]::Create(" wevtutil set-log $eventLogFullName /e:true /q:true") - #For any other computer, invoke command./ - $scriptTosetChannel=[Scriptblock]::Create(" wevtutil set-log $eventLogFullName /e:true /q:true") - if($Script:ThisCredential) { - Invoke-Command -ScriptBlock $scriptTosetChannel -ComputerName $Script:ThisComputerName -Credential $Script:ThisCredential + Invoke-Command -ScriptBlock $scriptTosetChannel -ComputerName $ComputerName -Credential $Credential } else { - Invoke-Command -ComputerName $Script:ThisComputerName -ScriptBlock $scriptTosetChannel + Invoke-Command -ComputerName $ComputerName -ScriptBlock $scriptTosetChannel } } - Write-Host "The $Channel event log has been Enabled. " + + Write-Verbose "The $Channel event log has been Enabled. " } catch { - Log -Error "Error : $_ " + Write-Error "Error : $_ " } - - } +} function Get-SingleRelevantErrorMessage(<#[System.Diagnostics.Eventing.Reader.EventRecord]#>$errorEvent) { @@ -784,5 +791,5 @@ C:\PS> Enable-DscEventLog -Channel "Debug" } -Export-ModuleMember -Function Trace-cDscOperation, Get-cDscOperation +Export-ModuleMember -Function Trace-cDscOperation, Get-cDscOperation, Enable-DscEventLog From 36852050b57bded78444b2ca82544a0626c450c8 Mon Sep 17 00:00:00 2001 From: "Tyson J. Hayes" Date: Tue, 21 Oct 2014 08:27:14 -0700 Subject: [PATCH 2/2] Fixing check for credentials --- Tooling/cDscDiagnostics/cDscDiagnostics.psm1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 b/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 index 0b3e06b..949278d 100644 --- a/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 +++ b/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 @@ -616,7 +616,7 @@ function Enable-DscEventLog [string] $Channel = "Analytic", [string] $ComputerName = $env:ComputerName, - [PSCredential] $Credential + $Credential ) $LogName = "Microsoft-Windows-Dsc" @@ -635,7 +635,7 @@ function Enable-DscEventLog # For any other computer, invoke command. $scriptTosetChannel = [Scriptblock]::Create(" wevtutil set-log $eventLogFullName /e:true /q:true") - if($Script:ThisCredential) + if($Credential) { Invoke-Command -ScriptBlock $scriptTosetChannel -ComputerName $ComputerName -Credential $Credential }