This Wiki article was created to share with you how it is possible to measure the response time of your DNS servers when performing name server lookups. This task can be easily achieved using Windows PowerShell by combining the use of Measure-Command and the Resolve-DnsName cmdlet.

If you would to measure the response time for a DNS server, you can run the following script:

#####################Variables#####################

$numberoftests = 10

###################################################

#####################Main#####################

cls

$dnsserver = "8.8.8.8"

$totalmeasurement = 0

$i = 0

while ($i -ne $numberoftests)

{

    $measurement = (Measure-Command {Resolve-DnsName www.bing.com -Server $dnsserver –Type A}).TotalSeconds

    $totalmeasurement += $measurement

    $i += 1

}

$totalmeasurement = $totalmeasurement / $numberoftests

"DNS Server: " + $dnsserver + ", Response time: " + $totalmeasurement + " seconds"

The script does the following:

  • It queries the DNS server that you have specified in $dnsserver variable to get the A record of www.bing.com (You can adjust the DNS query depending on your needs)
  • It queries the DNS server as many times as you have specified in $numberoftests variable
  • It measures and displays the average processing time of the DNS server

Important: The higher the number of you have specified for $numberoftests variable value, the more accurate results you get.

Below is a screen capture we get for results we had when running the script:

 

If you use an Active Directory Domain and your Domain Controllers are DNS servers, you can use the following the script to perform the same against all your DC/DNS servers:

#####################Variables#####################

$numberoftests = 10

###################################################

#####################Main#####################

cls

$myForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()

$domaincontrollers = $myforest.Sites | % { $_.Servers } | Select Name

foreach ($DomainController in $DomainControllers)

{

      $totalmeasurement = 0

      $i = 0

      while ($i -ne $numberoftests)

      {

            $measurement = (Measure-Command {Resolve-DnsName www.bing.com -Server $DomainController.name –Type A}).TotalSeconds

            $totalmeasurement += $measurement

            $i += 1

      }

      $totalmeasurement = $totalmeasurement / $numberoftests

      "Domain Controller: " + $DomainController.name + ", Response time: " + $totalmeasurement + " seconds"

}

 

Other Languages

This article is available in other languages.