PoshCode Archive  Artifact [7ff8f5d719]

Artifact 7ff8f5d7199cc401cdd4226dc0b320050b7e7d8548f94c4da32519aa029162c6:

  • File Get-NistNtpServer.ps1 — part of check-in [d48d7d2795] at 2018-06-10 13:20:53 on branch trunk — The Get-NistNtpServer function retrieves the list of NIST NTP server names, IP addresses, and locations. (user: Rich Kusak size: 1813)

# encoding: ascii
# api: powershell
# title: Get-NistNtpServer
# description: The Get-NistNtpServer function retrieves the list of NIST NTP server names, IP addresses, and locations.
# version: 1.0.0.0
# type: function
# author: Rich Kusak
# license: CC0
# function: Get-NistNtpServer
# x-poshcode-id: 3138
# x-archived: 2012-01-11T06:35:30
# x-published: 2012-01-02T10:06:00
#
#
function Get-NistNtpServer {
<#
	.SYNOPSIS
		Gets the list NIST NTP servers.

	.DESCRIPTION
		The Get-NistNtpServer function retrieves the list of NIST NTP server names, IP addresses, and locations.

	.EXAMPLE
		Get-NistNtpServer
		Returns the list of NIST NTP servers.

	.INPUTS
		None

	.OUTPUTS
		PSObject

	.NOTES
		Name: Get-NistNtpServer
		Author: Rich Kusak
		Created: 2011-12-31
		LastEdit: 2011-12-31 20:46
		Version: 1.0.0.0

	.LINK
		http://tf.nist.gov/tf-cgi/servers.cgi

#>

	[CmdletBinding()]
	param ()
	
	begin {
	
		$uri = 'http://tf.nist.gov/tf-cgi/servers.cgi'
		$webClient = New-Object System.Net.WebClient
		$filter = "$null", 'time.nist.gov', 'global address for all servers', 'Multiple locations'
		$i = 0

	} # begin
	
	end {
	
		try {
			$webpage = $webClient.DownloadString($uri)
		} catch {
			throw $_
		}
		
		$list = ([regex]::Matches($webpage, 'td align = "center">.*') | Select -ExpandProperty Value) -replace '.*>' | Where {
			 $filter -notcontains $_
		}
		
		$names = $list | Select-String '.*\.\D{2,3}$'
		$ips = $list | Select-String '^(\d{1,3}\.){3}\d{1,3}$'
		$locations = $list -like '*,*'
		
		foreach ($name in $names) {
			New-Object PSObject -Property @{
				'Name' = $name
				'IPAddress' = $ips[$i]
				'Location' = $locations[$i]
			}

			$i++
			
		} # foreach
	} # end
} # function Get-NistNtpServer