title: Getting back TIME information by Powershell
body: <p>I have the below code that looks at OS system and based on the build type it returns the NTP server they point to.</p>
  
  <p>However, it works fine on a match of 7601 (Windows Server 2008 R2) - but, for Windows Server 2003 servers I always get an error. For Windows Server 2003 servers you need to read a registry key.</p>
  
  <p>If I did the same query on the registry key locally on a server it works fine...although it reports back other stuff aswell as the registry key..</p>
  
  <p>here is the error:</p>
  
  <pre><code>NTPSource                                                   Server
  ---------                                                   ------
  The following error occurred: The procedure number is ou... SERV1
  </code></pre>
  
  <p>Here is the code:</p>
  
  <pre><code>$servers = @('SERV1','SERV2')
  $version = Get-WmiObject Win32_OperatingSystem -computer $servers | select buildnumber
  
  foreach ($server in $servers){
  
      if ($version -match '7601')
      {
      $ntps = w32tm /query /computer:$server /source
      new-object psobject -property @{
      Server = $Server
      NTPSource = $ntps
      }
      }
  elseif($version -match '3790')
  {
  
      Get-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Services\W32Time\Parameters' -Name Type
  
  }   
  }
  </code></pre>