Monthly Archive

Find the Time Server

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 0x9

Leave a Reply