reverse dns lookup get ip and name results together...

I’m performing a reverse dns lookup but I only get the name and not the IP used in my results. I would like to have both so I can match one to one. Can you help?

#Reverse IP Lookup
$IP1 = “”,

$PC = foreach ($p in $IP1)
[System.Net.Dns]::GetHostEntry($p).HostName | select-object $p, $p.hostname


My select object statement does not appear to be bringing in the data I need and it appears to be from the reverse dns lookup command I’m using.


you’re close…

foreach ($p in $ip1){
write-host "IP = $P, DNS =$PC"}

Nice and thank you but…

Is there a way to get it collected for foreach so that I can export to a csv?

Yes there is. There’s a cmdlet called export-csv. Look for some examples online, and then give it a shot. If you’re still having issues post your script and the error(s).

I appreciate all the help and what was first provided works great but wanted to say that I'm fully aware of the export-csv function but if you look at my first command this is usually how I get all the collected data to then be able to export it.

I can’t do the export inside the foreach because then it will just write over the file with every IP so I usually put the entire foreach to a variable and then pipe to export-csv. My issue is in getting these variables out are causing me the trouble. I have done this before with no problem but for some reason this command is giving me trouble. I’m sure I’m close but for some reason just not getting it.

[pre]$pc=foreach ($p in $ip1){

$pc1 | select-object $p, $pc1
write-host “IP = $P, DNS =$PC1”}
$PC | export-csv -path c:\file.csv$ [/pre]

foreach ($p in $ip1){
"$pc,$p"|add-content myout3.csv
$IP1 = '',''
$result = 
foreach ($ip in $IP1){
    Write-Verbose "Resolving $ip" -Verbose
    $dns = [System.Net.Dns]::GetHostEntry($ip)
    $dns | Select-Object HostName,

$result | export-csv .\dnsresult.csv -NoTypeInformation