# 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)
}
}
}