PowerShell: Check if a HostName is Resolvable on All Internal DNS Servers

# Check if servername is resolvable at all DCs

$serverName="MIGRATED-SHERVER"

function checkDns{
param(
$serverName,
$dnsServers=(Get-ADDomainController -Filter *).Name
)
$results="";
$dnsServers|%{
$resolve=Resolve-DnsName -Name $serverName -Server $_ -QuickTimeout -ea SilentlyContinue

$result=if($resolve.Name -ne $null){
"$_ has records of $serverName as $($resolve.IPAddress)`: Yes!`r`n";
}else{"$_ has records of $serverName`: No!`r`n";}
write-host $result -NoNewline;
$results+=$result;
}
return $results
}

checkDns -servername $serverName
checkDns -servername $serverName

Sample Result:

PS C:\temp> checkDns -servername $serverName
DNS001 has NO records of MIGRATED-SHERVER-old
DNS002 has NO records of MIGRATED-SHERVER-old
DNS003 has NO records of MIGRATED-SHERVER-old
DNS004 has NO records of MIGRATED-SHERVER-old
DNS005 has NO records of MIGRATED-SHERVER-old
DNS006 has NO records of MIGRATED-SHERVER-old
DNS007 has NO records of MIGRATED-SHERVER-old


PS C:\temp> checkDns -servername "MIGRATED-SHERVER"
DNS001 has records of MIGRATED-SHERVER
DNS002 has records of MIGRATED-SHERVER
DNS003 has records of MIGRATED-SHERVER
DNS004 has records of MIGRATED-SHERVER
DNS005 has records of MIGRATED-SHERVER
DNS006 has records of MIGRATED-SHERVER
DNS007 has records of MIGRATED-SHERVER

Leave a Reply

Your email address will not be published. Required fields are marked *