Sep 4 2011 12:16PM GMT
Posted by: Richard Siddaway
Active Directory, PowerShell v2, WMI
Clearing AD logging
Posted by: Richard Siddaway
Last time we looked at turning on logging – for one or more criteria. The normal state of diagnostic logging is None i.e. the options are set to zero. If we have only a few options set we can use set-logsetting to revert to no logging. Alternatively we can reset all logging to a zero state
function reset-logsetting{ [CmdletBinding(SupportsShouldProcess=$true)] param ( [parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [string]$computer ) BEGIN{ $HKLM = 2147483650 }#begin PROCESS{ Write-Verbose "Display Current Settings" get-logsetting -computer $computer $reg = [wmiclass]"\\$computer\root\default:StdRegprov" $key = "SYSTEM\CurrentControlSet\Services\NTDS\Diagnostics" switch ($computer){ "." {$computername = $env:COMPUTERNAME} "localhost" {$computername = $env:COMPUTERNAME} default {$computername = $computer} } 1..$logtype.Count | foreach { $value = $logtype["$_"] $level = $reg.SetDwordValue($HKLM, $key, $value, 0) ## REG_DWORD } Write-Verbose "Display New Settings" "" get-logsetting -computer $computer }#process END{}#end <# .SYNOPSIS Resets all AD diagnostic logging levels to none .DESCRIPTION Resets all AD diagnostic logging levels to none .PARAMETER Computer Computer Name .EXAMPLE reset-logsetting User will be prompted for server name .EXAMPLE reset-logsetting -computer server02 .LINK http://support.microsoft.com/kb/314980 #> }
This loops through the options and sets each to zero.




