This script will fetch the host name form IP address for a list of servers.
$listofIPs = Get-Content "c:\Ip.txt"
#Location of the file which contains the list of IP addresses
$ResultList = @()
foreach ($ip in $listofIPs)
{
$result = $null
$currentEAP = $ErrorActionPreference
$ErrorActionPreference = "silentlycontinue"
$result = [System.Net.Dns]::GetHostbyAddress("$ip")
$ErrorActionPreference = $currentEAP
If ($Result)
{
$Resultlist += $IP + "," + [string]$Result.HostName
}
Else
{
$Resultlist += $IP + " , No HostNameFound"
}
}$Resultlist | Out-File "c:\output.txt"
No comments:
Post a Comment