I want to ping a list of hostnames (lets say c:\hosts.txt) and get the IP Address. I then want to perform a reverse dns lookup on that IP. I do it today with “ping -a 192.168.25.68” as an example. I need to know the ones where the results of the lookup don’t match. Ex:
ping -n 1 WRKSTN101
Pinging WRKSTN101.mydomain.com [10.225.236.229] with 32 bytes of data:
Reply from 10.225.236.229: bytes=32 time<1ms TTL=128
ping -n 1 -a 10.225.236.229
Pinging SERVER208.mydomain.com [10.225.236.229] with 32 bytes of data:
Reply from 10.225.236.229: bytes=32 time<1ms TTL=128
Something like this should do the trick, but you may need to slightly tweak for your needs.
$Connection = Test-Connection -TargetName WRKSTN101.mydomain.com -Ping -Count 1
$DNS = Resolve-DNSName -Name $Connection.DisplayAddress
#$DNS will be a object that has multiple properties, probably the one you care about is the NameHost property
$DNS.NameHost