Finding Time Servers (And Reading All RegKey Values)

by Mar 26, 2014

Maybe you'd like to get a list of timeservers registered in the Registry database. Then you probably run code like this:

Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers'

 
$path = 'Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\DateTime\Servers'

$key = Get-Item -Path $path
Foreach ($valuename in $key.GetValueNames())
{
  if ($valuename -ne '')
  {
    $key.GetValue($valuename)
  }
} 

This code accesses the Registry key, and then uses its methods to get the value names, then dumps the values:

Twitter This Tip! ReTweet this Tip!