Complete powershell noob here. I am attempting to do the following:
- Import a list of IP addresses from a text file.
- Obtain the hostname of each IP address. If unable to, provide the failure reason.
- Export both IP address and hostname (or error) line by line in a CSV.
I was attempting to use the following script however I do not know what IP address is which since there are some errors:
get-content .\dnsip.txt | ForEach-Object {([system.net.dns]::GetHostByAddress($_)).hostname
Can someone help me write a script that would do this?
Thanks!