Created
July 9, 2014 04:43
-
-
Save nigamankit7/a7d765647c35ae55221b to your computer and use it in GitHub Desktop.
Reads a list of IPs and check their hostname. Save it in seperate files - resolved and unresolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Clear | |
$scriptpath = $MyInvocation.MyCommand.Path | |
$dir = Split-Path $scriptpath | |
$source = $dir + "\IPlist.txt" | |
$computers= gc $source | |
$DNS_Resolve = $dir + "\DNS_Resolved.csv" | |
Clear-Content $DNS_Resolve -ErrorAction "SilentlyContinue" | |
$DNS_Unresolve = $dir + "\DNS_Unesolved.csv" | |
Clear-Content $DNS_Unresolve -ErrorAction "SilentlyContinue" | |
foreach ($computername in $computers) | |
{ | |
try | |
{ | |
$HostName = [System.Net.Dns]::GetHostByAddress($computername).HostName | |
write-host "Hostname for $computername is :" $HostName -ForegroundColor GREEN | |
"$computername^$HostName" | Out-File -Enc UTF8 -Append $DNS_Resolve | |
} | |
catch | |
{ | |
write-host "Could not resolve $computername" -ForegroundColor RED | |
"$computername" | Out-File -Enc UTF8 -Append $DNS_Unresolve | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment