PowerShell for Windows Admins

Sep 4 2011   3:32AM GMT

Setting AD logging

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Now that we know what the options are we can look at switching them on.

function set-logsetting{             
param (             
 $HKLM = 2147483650            
 if ($logtype.Values -notcontains $setting){            
   Throw "Incorrect setting - please use get-logsettingoptions"            
 $reg = [wmiclass]"\\$computer\root\default:StdRegprov"            
 $key = "SYSTEM\CurrentControlSet\Services\NTDS\Diagnostics"            
 switch ($computer){            
   "."         {$computername = $env:COMPUTERNAME}            
   "localhost" {$computername = $env:COMPUTERNAME}            
   default     {$computername = $computer}            
 $result = $reg.SetDwordValue($HKLM, $key, $setting, $level)  ## REG_DWORD            
Sets AD diagnostic logging levels 

Sets AD diagnostic logging levels 

.PARAMETER  Computer
Computer Name

The setting to be logged

The level of logging to be applied

set-logsetting -computer server02 -setting "5 Replication Events" -level 1

get-logsettingoptions | 
foreach {set-logsetting -computer server02 -setting $_ -level 2}

get-logsettingoptions | 
where {$_ -like "19*"} | 
foreach {set-logsetting -computer server02 -setting $_ -level 5}


The setting and level are input as parameters. The level can be checked as a range – the setting to log is checked against the hash table of logging types. The WMI SetDWord method is used to perform the change. A few of the ways the setting to use can be input are shown in the help examples.

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: