I'm trying to write a script that will take input from a .txt file of IP address. Do a reverse DNS lookup to get the hostname of the IP address and then export that data into .csv file.
Here is what I have so far.
# getting the IP's from the file
$IPADDR = Get-Content "C:\Users\douglasfrancis\Desktop\IP_Test.txt"
ForEach ($IPADDR in $IPADDR)
{
[System.Net.DNS]::GetHostbyAddress($IPADDR) | Add-Member -Name IP -Value $IPADDR - MemberType NoteProperty -PassThru | select IP, HostName | sort -property Hostname | export- csv "C:\Users\douglasfrancis\Desktop\ReverseLookup.csv"
}
How it is now the created CSV file will have the column heads that I assigned and the last IP address in the list with its hostname. So somehow its dropping everything else.
If I run it with the export-csv commented out then all the IP's are displayed in the console but are not sorted by hostname.
I've used this same basic pipe before with no issues so I'm kinda at a loss for what is going on here. Any help would be awesome.
Thanks,