PowerShell Genie

Compare DNS answers across servers

Script 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

The loop asks each server in $DnsServers to resolve $Name and stamps the responding server onto every record with a calculated property.

The script

1PS> $Name = "example.com"
2PS> $DnsServers = "DC01", "DC02"
3PS> foreach($Server in $DnsServers){ Resolve-DnsName $Name -Server $Server | Select-Object @{ Name = "Server"; Expression = { $Server } },Name,Type,IPAddress }

Script reader

Inspect before you run

Inspection only

Inspect the script below. It does not run in this browser.

Inspection only — no command has run.

    Show reference output
    1 Server
    2 ------
    3 DC01
    Inspect this example’s structure

    Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

    $Name = "example.com" $DnsServers = "DC01", "DC02" foreach($Server in $DnsServers){ Resolve-DnsName $Name -Server $Server | Select-Object @{ Name = "Server"; Expression = { $Server } },Name,Type,IPAddress }
    1. Stage 1$NamePositional values or no named parameters

      How it works

      The loop asks each server in $DnsServers to resolve $Name and stamps the responding server onto every record with a calculated property. Name, Type, and IPAddress come straight from the response, so identical answers appear as identical rows and a divergence stands out immediately.

      Adapting it

      Add -Type to the Resolve-DnsName call when the record in question is not an address record, and pass -DnsOnly so the local resolver cache stays out of the comparison.

      If the result is unexpected

      DNS servers return different answers for the same name.

      Split DNS, cache state, record type and replication can make answers differ legitimately.

      1. Query the same fully qualified name and record type against each named server.

      Validate the result

      Each answer is tied to its responding server, record type and observation time.

      Keep the check reliable

      Define the expected DNS view before treating every answer difference as a fault.

      Primary documentation

      PowerShell objects and pipelines documentation

      Continue
      Genie guideCompare DNS answers across servers

      The loop asks each server in $DnsServers to resolve $Name and stamps the responding server onto every record with a calculated property.