propecia kaufen

 06 Sep 2013 @ 7:42 AM 

Some time ago I was asked to write a PowerShell script to do an inventory of the time server (NTP) configuration on clients.
Today I was asked the same, so I grabbed my old script, expanded it a little and here you go :-)

function Get-TimeServer {
	Gets the time server as configured on a computer.
	Gets the time server as configured on a computer.
	The default is localhost but can be used for remote computers.
	Get-TimeServer -ComputerName "Server1"
	Get-TimeServer -ComputerName "Server1","Server2"
	Get-TimeServer -Computer "Server1","Server2"
	Get-TimeServer "Server1","Server2"
	Written by Jeff Wouters.
	param ( 
	begin {
		$HKLM = 2147483650
	process {
		foreach ($Computer in $ComputerName) {
			$TestConnection = Test-Connection -ComputerName $Computer -Quiet -Count 1
			$Output = New-Object -TypeName psobject
			$Output | Add-Member -MemberType 'NoteProperty' -Name 'ComputerName' -Value $Computer
            $Output | Add-Member -MemberType 'NoteProperty' -Name 'TimeServer' -Value "WMI Error"
			$Output | Add-Member -MemberType 'NoteProperty' -Name 'Type' -Value "WMI Error"
			if ($TestConnection) {				
				try {
                    $reg = [wmiclass]"\\$Computer\root\default:StdRegprov"
				    $key = "SYSTEM\CurrentControlSet\Services\W32Time\Parameters"
				    $servervalue = "NtpServer"
				    $server = $reg.GetStringValue($HKLM, $key, $servervalue)
				    $ServerVar = $server.sValue -split ","
				    $Output.TimeServer = $ServerVar[0]
    				$typevalue = "Type"
                    $type = $reg.GetStringValue($HKLM, $key, $typevalue)
                    $Output.Type = $Type.sValue				
                } catch {
			} else {
Posted By: Jeff Wouters
Last Edit: 16 Apr 2014 @ 11:54 AM


  • Shay Levy

    You might want to check the w32tm utility:

    w32tm /query /computer:pc1 /source

  • Jeff Wouters

    That output is tricky to put into a CSV and do some selecting/sorting on it, that’s why we’v used the script I posted :-)

  • weiyentan

    Thanks for the article. Can we run it against a list of servers in a text file?

  • Jeff Wouters

    Hi Weiyentan,
    Sure, you can call it like so:
    Get-TimeServer -ComputerName (get-content C:\Users\Jeff\Desktop\123.txt)

  • Thunderlight

    Thanks for the script, made some adjustments to accept pipeline input but its working great

  • Jeff Wouters

    Hi Marco,
    Happy to read you found it useful :-)

 Last 50 Posts
Change Theme...
  • Users » 1
  • Posts/Pages » 365
  • Comments » 561
Change Theme...
  • VoidVoid « Default
  • LifeLife
  • EarthEarth
  • WindWind
  • WaterWater
  • FireFire
  • LightLight


    No Child Pages.


    No Child Pages.


    No Child Pages.

Health Check

    No Child Pages.