Hello folks, I’m still a bit of a powershell newbie and hoping I can get your help in figuring out where I’m going wrong. Here’s my script so far:
Import-Module xDscDiagnostics function Get-DSCLogStatus { [OutputType([string])] param ( [Parameter(Mandatory)] [string] $IsEnabled ) switch -Wildcard ($IsEnabled) { '*True*' { return 'True' } default { return 'False' } } } function get-dsclogname { [OutputType([string])] param ( [Parameter(Mandatory)] [string] $log ) switch -wildcard ($log) { '*Analytic' { return 'Analytic' } '*Debug' { return 'Debug' } Default { return 'Operational' } } } $DSCLog = Get-WinEvent -Force -ListLog * | Where LogName -Match "Microsoft-Windows-DSC" | Select-Object LogName, isEnabled $DSCLogStatus = @{ AllLogs = @( foreach ($Log in $DSCLog) { @{ LogNames = Get-DSCLogname -Log $Log.logname | Out-String LogStatus = Get-DSCLogStatus -isenabled $Log.isEnabled } } ) } function EnableDscLogging { foreach ($Logs in $dsclogstatus.alllogs) { If ($logs.logstatus -eq $false) { #Update-xDscEventLogStatus -Channel $logs.lognames -status Enabled Invoke-expression "Update-xDscEventLogStatus -Channel Debug -status Enabled" } ElseIf ($logs.logstatus -eq $true) { (Write-Warning -Message "Eventlog already enabled") } } }
Objective: Run a ‘foreach disabled log’ and fill in the “channel” property with the value containing the truncated name (Analytic, Debug, or Operational) of said log, allowing me to use the update-xdsceventlogstatus command to activate the logs. I will later convert this into a composite resource that I can use in DSC to pick/choose which types of targets should have analytic/debug logs enabled.
Problem: see here:
If ($logs.logstatus -eq $false) { #Update-xDscEventLogStatus -Channel $logs.lognames -status Enabled Invoke-expression "Update-xDscEventLogStatus -Channel Debug -status Enabled" }
The code I need to fill in the channel (that I have commented) doesn’t work, but I tried using the 2nd line as a ‘test’ to ensure the other sections of my code are okay and it does indeed activate the debug channel, which I’m interpreting as it coming back and acknowledging that the status of at least one of the logs is “disabled”.
I’m kinda scratching my head at this point. I still learning how to fully utilize hash tables to their fullest. Help is much appreciated!