Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nigamankit7/a7d765647c35ae55221b to your computer and use it in GitHub Desktop.
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
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