PowerShell for Windows Admins

Jun 9 2010   12:56PM GMT

Reading the Registry – time service

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

I recently needed to look at the time service configuration on a number of machines.  We can use what we have learned about reading registry keys with WMI to do this

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
$HKLM = 2147483650 #HKEY_LOCAL_MACHINE
$reg = [wmiclass]‘\\.\root\default:StdRegprov’

$key = "SYSTEM\CurrentControlSet\Services\W32Time\Config"
$value = "MaxPosPhaseCorrection"
$maxpos = $reg.GetDwordValue($HKLM, $key, $value)  ## REG_DWORD
 
$value = "MaxPosPhaseCorrection"
$maxneg = $reg.GetDwordValue($HKLM, $key, $value)  ## REG_DWORD

$key = "SYSTEM\CurrentControlSet\Services\W32Time\Parameters"
$value = "NtpServer"
$srvr = $reg.GetStringValue($HKLM, $key, $value)  ## REG_SZ

"Time Settings"
"Server : $($srvr.sValue)"
"Max Positive : $(($maxpos.uvalue)/3600) hours"
"Max Negative : $(($maxneg.uvalue)/3600) hours"

Set the constant for HKLM hive and create a WMI object.  I’ve used the local machine but change the string to

‘\\computer_name\root\default:StdRegProv’ if you want to access a remote machine.

We then set the key and the value we want to read and call the appropriate method.  As a finished I’ve displayed the data in a nicely formatted table.  The maximum negative and positive values are given in seconds so I’ve converted them to hours to be more understandable.

 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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: