get-content "C:\list\hnames.txt" |
Select-Object `
@{n='IP';e={ $_ }},
@{n='ReverseLookup';e={ [System.Net.Dns]::GetHostbyAddress($_).HostName }} |
Select-Object *, @{n='ForwardLookup';e={ if ($_.ReverseLookup) { [System.Net.Dns]::GetHostEntry($_.ReverseLookup).AddressList } }} |
Export-CSV C:\list\RDNS2.csv -NoTypeInformation
Obviously we don't get to do the forward lookup on the result of the reverse unless the reverse lookup returned something.Get-content "C:\list\hnames.txt" | ForEach-Object {
try { $DnsCheck = [System.Net.Dns]::GetHostEntry($_) } catch { }
if ($?) {
if ([IPAddress]::TryParse($_, [Ref]$null)) {
$DnsCheck = $DnsCheck.Hostname
} else {
$DnsCheck = $DnsCheck.AddressList
}
} else {
$DnsCheck = $null
}
[PSCustomObject]@{
'Hostname/IP' = $_
'DNS Check' = $DnsCheck
}
} | Export-CSV C:\list\RDNS2.csv -NoTypeInformation
Chris
Get-content "C:\list\hnames.txt" | ForEach-Object {
try { $DnsCheck = [System.Net.Dns]::GetHostEntry($_) } catch { }
if ($?) {
if ([IPAddress]::TryParse($_, [Ref]$null)) {
$DnsCheck = $DnsCheck.Hostname
} else {
$DnsCheck = $DnsCheck.AddressList
}
} else {
$DnsCheck = $null
}
$Return = New-Object PSObject
Add-Member 'Hostname/IP' -MemberType NoteProperty -Value $_ -InputObject $Return
Add-Member 'DNS Check' -MemberType NoteProperty -Value $DnsCheck -InputObject $Return
$Return
} | Export-CSV C:\list\RDNS2.csv -NoTypeInformation
Chris
Open in new window
Chris