Hi Everyone,
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:Listv3Devices.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:
1. all of the result is always displayed as down ?
2. 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.albertwt2011-10-12 18:37:04
Script to convert IP to DNS and DNS to IP ?
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- ITEngineer
- Posts: 216
- Last visit: Thu Mar 23, 2023 5:45 pm
- Has voted: 4 times
- ITEngineer
- Posts: 216
- Last visit: Thu Mar 23, 2023 5:45 pm
- Has voted: 4 times
Script to convert IP to DNS and DNS to IP ?
Hi JVierra,
What I'd like to achieve is that I need to test the host/server availability using ping from the mixed list of IP address and hostname.
What I'd like to achieve is that I need to test the host/server availability using ping from the mixed list of IP address and hostname.
/* IT Engineer */