Get-TimeServer.ps1
something exciting
Some information about the exciting thing
Table of contents generated with markdown-toc
Script
function Get-TimeServer {
<#
.Synopsis
Gets the time server as configured on a computer.
.DESCRIPTION
Gets the time server as configured on a computer.
The default is localhost but can be used for remote computers.
.EXAMPLE
Get-TimeServer -ComputerName "Server1"
.EXAMPLE
Get-TimeServer -ComputerName "Server1","Server2"
.EXAMPLE
Get-TimeServer -Computer "Server1","Server2"
.EXAMPLE
Get-TimeServer "Server1","Server2"
.NOTES
Written by Jeff Wouters.
#>
[CmdletBinding()]
param (
[parameter(mandatory = $true, position = 0)]
[alias("computer")]
[array]$ComputerName
)
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
$Output
}
catch {
}
}
else {
}
}
}
}
Get-TimeServer -ComputerName $Server.Name
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simple click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.