Introduction
Debug/verbose logging! A topic which every ConfigMgr admin will have to get familiar with sooner or later. Lazy as one can be, I usually Google the requirements every time I need it, so I figured it was time to make something more permanent and more clever.
There are a billion blog posts on the topic already, but as far as my Google skills serves me, no one is using the run script feature and no one is providing complete scripts for the purpose. So this is me doing that. A complete solution for your copy/paste pleasure
Powershell
I initially did a complete Powershell script made to be run outside of ConfigMgr, which accepts parameters to both enable and disable debug/verbose logging. I’m making this available for download here if interested.
>> https://gallery.technet.microsoft.com/Enable-Disable-Debug-743bdcae <<
A quick snip of when run manually below:
Then I realized that doing this with the Run Script feature is much more appealing, so I broke the script into two pieces:
Enable Debug/Verbose Logging
$GlobalLoggingPath = "HKLM:\SOFTWARE\Microsoft\CCM\Logging\@GLOBAL" $DebugLoggingPath = "HKLM:\SOFTWARE\Microsoft\CCM\Logging\DebugLogging" try { New-ItemProperty -Path $GlobalLoggingPath -Name LogLevel -PropertyType DWORD -Value 0 -Force | Out-Null New-ItemProperty -Path $GlobalLoggingPath -Name LogMaxHistory -PropertyType DWORD -Value 4 -Force | Out-Null New-ItemProperty -Path $GlobalLoggingPath -Name LogMaxSize -PropertyType DWORD -Value 5242880 -Force | Out-Null # This translates into 5MB } catch { return 1 break } if (-NOT(Test-Path -Path $DebugLoggingPath)) { try { New-Item -Path $DebugLoggingPath -ItemType Directory –Force | Out-Null } catch { return 1 break } if (Test-Path -Path $DebugLoggingPath) { try { New-ItemProperty -Path $DebugLoggingPath -Name Enabled -PropertyType String -Value True -Force | Out-Null } catch { return 1 break } } } elseif (Test-Path -Path $DebugLoggingPath) { try { New-ItemProperty -Path $DebugLoggingPath -Name Enabled -PropertyType String -Value True -Force | Out-Null } catch { return 1 break } } $VerifyGlobalLogging = Get-ItemProperty -Path $GlobalLoggingPath $VerifyDebugLogging = Get-ItemProperty -Path $DebugLoggingPath if (($VerifyGlobalLogging.LogLevel -eq 0) -AND ($VerifyGlobalLogging.LogMaxHistory -eq 4) -AND ($VerifyGlobalLogging.LogMaxSize -eq 5242880) -AND ($VerifyDebugLogging.Enabled -eq "True")) { Write-Output "SUCESS" return 0 } else { Write-Output "FAILURE" return 1 }
Disable Debug/Verbose Logging
$GlobalLoggingPath = "HKLM:\SOFTWARE\Microsoft\CCM\Logging\@GLOBAL" $DebugLoggingPath = "HKLM:\SOFTWARE\Microsoft\CCM\Logging\DebugLogging" try { New-ItemProperty -Path $GlobalLoggingPath -Name LogLevel -PropertyType DWORD -Value 1 -Force | Out-Null New-ItemProperty -Path $GlobalLoggingPath -Name LogMaxHistory -PropertyType DWORD -Value 1 -Force | Out-Null New-ItemProperty -Path $GlobalLoggingPath -Name LogMaxSize -PropertyType DWORD -Value 250000 -Force | Out-Null } catch { return 1 break } if (Test-Path -Path $DebugLoggingPath) { try { Remove-Item -Path $DebugLoggingPath -Force | Out-Null } catch { return 1 break } } $VerifyGlobalLogging = Get-ItemProperty -Path $GlobalLoggingPath $VerifyDebugLogging = Test-Path -Path $DebugLoggingPath if (($VerifyGlobalLogging.LogLevel -eq 1) -AND ($VerifyGlobalLogging.LogMaxHistory -eq 1) -AND ($VerifyGlobalLogging.LogMaxSize -eq 250000) -AND ($VerifyDebugLogging -eq $false)) { Write-Output "SUCESS" return 0 } else { Write-Output "FAILURE" return 1 }
Run Script
Now, put above two scripts to use with the run script feature in ConfigMgr by creating and approving them in the console as shown below.
Locate the device where you want to enable/disable debug logging and select to run script
The scripts are made to give you either SUCESS 0 or FAILURE 1 as output when run:
ENJOY
2 thoughts on “Enable and disable ConfigMgr client debug logging in a jiffy using Powershell and Run Script”