I'd appreciate your efforts in helping me modifying the script below so that it can check & convert the list of IPAddress and hostname into something like:
DomainController1 - 10.1.1.10 - UP
CoreGatewayRTR1 - 10.1.1.254 - DOWN
JohnPC01 - NO-IP-Address - DOWN
LindaLaptop02 - 10.1.1.234 - DOWN
.
.
.
it is a challenge for me to convert IP to DNSName and DNSName to IP then check the online status based on Ping,
the following is the script that I can come up with so far:
$computers= gc C:\ListOfDevices.txt
foreach ($computername in $computers) {
$DNS = [System.Net.Dns]::GetHostEntry($ComputerName)
$HostName = $DNS.HostName
$IP = $DNS.AddressList
Trap { Continue }
if (Test-Connection $DNS -erroraction SilentlyContinue -Count 1 ) {
write-host "$Hostname - $IP - UP" -ForegroundColor GREEN
}
else {
write-host "$Hostname - $IP - DOWN" -ForegroundColor RED
}
}
However, the above script still got minor logic error as follows:
all of the result is always displayed as down ?
some of the result is always duplicated even though the IP address of that particular host is only one ?
Any kind of help would be greatly appreciated.
Thanks.