PowerShell for Windows Admins

Sep 5 2011   12:33PM GMT

Find the Time Server



Posted by: Richard Siddaway
Tags:
Active Directory
PowerShell v2
Registry
WMI

No its not the latest Internet game.

Active Directory synchronises the computer clock times. To know what server is being used

function get-timeserver{             
[CmdletBinding(SupportsShouldProcess=$true)]             
param (             
[parameter(Position=0,            
   Mandatory=$true,            
   ValueFromPipeline=$true,             
   ValueFromPipelineByPropertyName=$true)]            
   [string]$computer             
)             
BEGIN{            
 $HKLM = 2147483650            
}#begin             
            
PROCESS{            
 $reg = [wmiclass]"\\$computer\root\default:StdRegprov"            
            
 $key = "SYSTEM\CurrentControlSet\Services\W32Time\Parameters"            
             
 switch ($computer){            
   "."         {$computername = $env:COMPUTERNAME}            
   "localhost" {$computername = $env:COMPUTERNAME}            
   default     {$computername = $computer}            
 }            
             
 $value = "NtpServer"            
 $server = $reg.GetStringValue($HKLM, $key, $value)  ## REG_SZ            
 $server.sValue -split ","            
              
}#process             
END{}#end            
            
}

Read the "SYSTEM\CurrentControlSet\Services\W32Time\Parameters" key for the Ntpserver value.  Its a string so use GetstringValue(). It is possible to define multiple time servers so split the string on “,”

Ignore the final value of 0×9

 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: