From c40e700bf37b6be08e68c563f392f1d75a63beab Mon Sep 17 00:00:00 2001 From: "Tyson J. Hayes" Date: Mon, 20 Oct 2014 23:28:38 -0700 Subject: [PATCH 1/2] Modifying Test-DscEventLogStatus to be exportable --- Tooling/cDscDiagnostics/cDscDiagnostics.psm1 | 49 ++++++-------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 b/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 index f3406a2..aaa99e2 100644 --- a/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 +++ b/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 @@ -375,39 +375,17 @@ function Get-AllGroupedDscEvents # Function to prompt the user to set an event log, for the channel passed in as parameter # - function Test-DscEventLogStatus - { - param($Channel="Analytic") - $LogDetails=Get-WinEvent -ListLog "$Script:DscLogName/$Channel" - if($($LogDetails.IsEnabled)) - { - return $true - } - $numberOfTries=0; - while($numberOfTries -lt 3) - { - $enableLog=Read-Host "The $Channel log is not enabled. Would you like to enable it?(y/n)" - if($enableLog.ToLower() -eq "y") - { - Enable-DscEventLog -Channel $Channel - Write-Host "Execute the operation again to record the events. Events were not recorded in the $Channel channel since it was disabled" - break - } - - elseif($enableLog.ToLower() -eq "n") - { - Log -Error "The $Channel events cannot be read until it has been enabled" - break - } - else - { - Log -Error "Could not understand the option, please try again" - } - $numberOfTries++ - } - return $false +function Test-DscEventLogStatus +{ + param + ( + [ValidateSet("Debug", "Analytic", "Operational")] + $Channel = "Analytic", + $ComputerName = $env:ComputerName + ) - } + return $(Get-WinEvent -ListLog "Microsoft-Windows-DSC/$Channel" -ComputerName $ComputerName).IsEnabled +} #This function gets all the DSC runs that are recorded into the event log. function Get-SingleDscOperation @@ -697,8 +675,9 @@ C:\PS> Enable-DscEventLog -Channel "Debug" Log -Error "Please enter a valid Sequence ID . All sequence IDs can be seen after running command Get-cDscOperation . " -ForegroundColor Red return } - $null=Test-DscEventLogStatus -Channel "Analytic" - $null=Test-DscEventLogStatus -Channel "Debug" + if (! (Test-DscEventLogStatus -Channel "Analytic") ) { Write-Warning "Analytic log not enabled. Please run: Enable-DscEventLog -Channel 'Analytic'" } + + if (! (Test-DscEventLogStatus -Channel "Debug") ) { Write-Warning "Debug log not enabled. Please run: Enable-DscEventLog -Channel 'Debug'" } #endregion @@ -784,5 +763,5 @@ C:\PS> Enable-DscEventLog -Channel "Debug" } -Export-ModuleMember -Function Trace-cDscOperation, Get-cDscOperation +Export-ModuleMember -Function Trace-cDscOperation, Get-cDscOperation, Test-DscEventLogStatus From 56f83b3291a7ba6df3a08ee9b354f193eb852424 Mon Sep 17 00:00:00 2001 From: "Tyson J. Hayes" Date: Tue, 21 Oct 2014 08:20:15 -0700 Subject: [PATCH 2/2] Modifying Test-DscLogStatus to accept credentials. --- Tooling/cDscDiagnostics/cDscDiagnostics.psm1 | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 b/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 index aaa99e2..650180f 100644 --- a/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 +++ b/Tooling/cDscDiagnostics/cDscDiagnostics.psm1 @@ -380,11 +380,19 @@ function Test-DscEventLogStatus param ( [ValidateSet("Debug", "Analytic", "Operational")] - $Channel = "Analytic", - $ComputerName = $env:ComputerName + [string] $Channel = "Analytic", + [string] $ComputerName = $env:ComputerName, + $Credential ) - return $(Get-WinEvent -ListLog "Microsoft-Windows-DSC/$Channel" -ComputerName $ComputerName).IsEnabled + if ($Credential) + { + $(Get-WinEvent -ListLog "Microsoft-Windows-DSC/$Channel" -ComputerName $ComputerName -Credential $Credential).IsEnabled + } + else + { + return $(Get-WinEvent -ListLog "Microsoft-Windows-DSC/$Channel" -ComputerName $ComputerName).IsEnabled + } } #This function gets all the DSC runs that are recorded into the event log. @@ -663,7 +671,6 @@ C:\PS> Enable-DscEventLog -Channel "Debug" param( [UInt32]$SequenceID=1, #latest is by default [Guid]$JobId - ) @@ -675,9 +682,9 @@ C:\PS> Enable-DscEventLog -Channel "Debug" Log -Error "Please enter a valid Sequence ID . All sequence IDs can be seen after running command Get-cDscOperation . " -ForegroundColor Red return } - if (! (Test-DscEventLogStatus -Channel "Analytic") ) { Write-Warning "Analytic log not enabled. Please run: Enable-DscEventLog -Channel 'Analytic'" } + if (! (Test-DscEventLogStatus -Channel "Analytic" -ComputerName $Script:ThisComputerName -Credential $Script:ThisCredential ) ) { Write-Warning "Analytic log not enabled. Please run: Enable-DscEventLog -Channel 'Analytic'" } - if (! (Test-DscEventLogStatus -Channel "Debug") ) { Write-Warning "Debug log not enabled. Please run: Enable-DscEventLog -Channel 'Debug'" } + if (! (Test-DscEventLogStatus -Channel "Debug" -ComputerName $ThisComputerName -Credential $Script:ThisCredential) ) { Write-Warning "Debug log not enabled. Please run: Enable-DscEventLog -Channel 'Debug'" } #endregion