Skip to content
This repository was archived by the owner on May 15, 2018. It is now read-only.

Modifying Test-DscEventLogStatus to be exportable #94

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 19 additions & 33 deletions Tooling/cDscDiagnostics/cDscDiagnostics.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -375,39 +375,25 @@ 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))
function Test-DscEventLogStatus
{
param
(
[ValidateSet("Debug", "Analytic", "Operational")]
[string] $Channel = "Analytic",
[string] $ComputerName = $env:ComputerName,
$Credential
)

if ($Credential)
{
return $true
$(Get-WinEvent -ListLog "Microsoft-Windows-DSC/$Channel" -ComputerName $ComputerName -Credential $Credential).IsEnabled
}
$numberOfTries=0;
while($numberOfTries -lt 3)
else
{
$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 $(Get-WinEvent -ListLog "Microsoft-Windows-DSC/$Channel" -ComputerName $ComputerName).IsEnabled
}
return $false

}
}

#This function gets all the DSC runs that are recorded into the event log.
function Get-SingleDscOperation
Expand Down Expand Up @@ -685,7 +671,6 @@ C:\PS> Enable-DscEventLog -Channel "Debug"
param(
[UInt32]$SequenceID=1, #latest is by default
[Guid]$JobId

)


Expand All @@ -697,8 +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
}
$null=Test-DscEventLogStatus -Channel "Analytic"
$null=Test-DscEventLogStatus -Channel "Debug"
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" -ComputerName $ThisComputerName -Credential $Script:ThisCredential) ) { Write-Warning "Debug log not enabled. Please run: Enable-DscEventLog -Channel 'Debug'" }

#endregion

Expand Down Expand Up @@ -784,5 +770,5 @@ C:\PS> Enable-DscEventLog -Channel "Debug"
}


Export-ModuleMember -Function Trace-cDscOperation, Get-cDscOperation
Export-ModuleMember -Function Trace-cDscOperation, Get-cDscOperation, Test-DscEventLogStatus