PoshCode Archive  Artifact [6f67f6b4c4]

Artifact 6f67f6b4c45d1aede3aef6e97244f62d9aee7c508d6553547449b35a179910e9:

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

# encoding: ascii
# api: powershell
# title: Get-NistNtpServer
# description: The Get-NistNtpServer function retrieves the list of NIST NTP server names, IP addresses, locations, and status.
# version: 1.1.0.0
# type: function
# author: Rich Kusak
# license: CC0
# function: Get-NistNtpServer
# x-poshcode-id: 3468
# x-archived: 2012-06-22T05:42:19
# x-published: 2012-06-20T17:42: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, locations, and status.

	.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: 2012-06-18 18:31
		Version: 1.1.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 -TypeName System.Net.WebClient
		$regex = '(td align = "center">.*)|(;">.*)'

	} # begin
	
	end {
	
		try {
			$webpage = $webClient.DownloadString($uri)
		} catch {
			throw $_
		}
		
		$list = ([regex]::Matches($webpage, $regex) | Select-Object -ExpandProperty Value) -replace '.*>' | Where-Object {
			 $_ -notlike $null
		}
		
		for ($i = 0 ; $i -lt $list.Count ; $i += 4) {
			New-Object -TypeName PSObject -Property @{
				'Name' = $list[(0 + $i)]
				'IPAddress' = $list[(1 + $i)]
				'Location' = $list[(2 + $i)]
				'Status' = $list[(3 + $i)]
		
			} | Select-Object -Property 'Name','IPAddress','Location','Status'
		
		} # for
	} # end
} # function Get-NistNtpServer