Posted On January 6, 2020

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

kimconnect 0 comments
blog.KimConnect.com >> Codes , Networking >> 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 *

Related Post

Configure VPN from AWS to CPE (Juniper Router)

1. Create VPN connection from AWS portal and download the configuration file2. Import the configuration…

PowerShell: Inter-Domain SMB Shares Mounting

# interDomainFileCopy.ps1 # Note: this is a quick and dirty method. Password security must be…

PowerShell: How to Replace a System File – For Experimentation Purposes

# When attempting to rename a system protected file such as notepad.exe $notepadExe='C:\Windows\system32\notepad.exe' $newNotePadExe='C:\Users\rambo\Desktop\notepad.exe' rename-item…