PoshCode Archive  Artifact [de493de1b0]

Artifact de493de1b0c54da3db2090aa72574758b299a38054e37d8e6389654bf513e381:

  • File Get-HostEntry.ps1 — part of check-in [9ee2692d1b] at 2018-06-10 13:12:14 on branch trunk — Queries DNS to return the host name and associated IP addresses, given either an IP address or a host name via the pipeline or parameter (accepts arrays). (user: Nathan Hartley size: 869)

# encoding: ascii
# api: powershell
# title: Get-HostEntry.ps1
# description: Queries DNS to return the host name and associated IP addresses, given either an IP address or a host name via the pipeline or parameter (accepts arrays).
# version: 0.1
# author: Nathan Hartley
# license: CC0
# x-poshcode-id: 2558
# x-archived: 2011-03-24T17:36:06
# x-published: 2011-03-14T13:42:00
#
#
param (
	[parameter(Mandatory=$true, ValueFromPipeline=$true)]
		[String[]]$HostnameOrIPs
)
process {
	ForEach ($HostnameOrIP in $HostnameOrIPs) {
		try {
			$result = [System.Net.Dns]::GetHostEntry($HostnameOrIP)
			"" | select @{Name='HostName'; Expression={$result.HostName}}, @{Name='AddressList'; Expression={$result.AddressList}}
		}
		catch {
			Write-Warning ("[{0}] Lookup failed: {1}" -f $HostnameOrIP, $_.exception.InnerException.message)
		}
	}
}