Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to use a command-line tool to list a (primary) zone's configured secondary servers, if any.

Dnscmd comes close with:

dnscmd server /ZoneResetSecondaries:[list of secondaries]

But, I don't want to clobber any current settings, I just want to review them. PowerShell (even on Server 2012) doesn't seem to help.


share|improve this question
Ah, I just found it. Use dnscmd server /EnumZones then parse the list of zones to get zonenames run dnscmd server /ZoneInfo zonename and finally parse the output for Zone Secondaries – jcarpio Apr 15 '14 at 16:07
up vote 4 down vote accepted

You are most correct in that you can:

  1. Enumerate the zones and look for the "Primary" ones
  2. Retrieve zone info for each zone

I've previously written about parsing dnscmd output using PowerShell, and this should accomplish step 1:

function Get-DNSZones
    [String]$ComputerName = "."

    $enumZonesExpression = "dnscmd $ComputerName /enumzones"
    $dnscmdOut = Invoke-Expression $enumZonesExpression
    if(-not($dnscmdOut[$dnscmdOut.Count - 2] -match "Command completed successfully."))
        Write-Error "Failed to enumerate zones"
        return $false
        # The output header can be found on the fifth line: 
        $zoneHeader = $dnscmdOut[4]

        # Let's define the the index, or starting point, of each attribute: 
        $d1 = $zoneHeader.IndexOf("Zone name")
        $d2 = $zoneHeader.IndexOf("Type")
        $d3 = $zoneHeader.IndexOf("Storage")
        $d4 = $zoneHeader.IndexOf("Properties")

        # Finally, let's put all the rows in a new array:
        $zoneList = $dnscmdOut[6..($dnscmdOut.Count - 5)]

        # This will store the zone objects when we are done:
        $zones = @()

        # Let's go through all the rows and extrapolate the information we need:
        foreach($zoneString in $zoneList)
            $zoneInfo = @{
                Name       =   $zoneString.SubString($d1,$d2-$d1).Trim();
                ZoneType   =   $zoneString.SubString($d2,$d3-$d2).Trim();
                Storage    =   $zoneString.SubString($d3,$d4-$d3).Trim();
                Properties = @($zoneString.SubString($d4).Trim() -split " ")
            $zoneObject = New-Object PSObject -Property $zoneInfo
            $zones += $zoneObject

        return $zones

Now you can list all Primary zones with:

Get-DNSZones|Where-Object {$_.ZoneType -eq 'Primary'}

You could then use the Zone array to automate the lookup for all the primary zones:

$PrimaryZones = Get-DNSZones|Where-Object {$_.ZoneType -eq 'Primary'}
$PrimaryZones |% {$out = iex "dnscmd . /ZoneInfo $($_.ZoneName) |find `"Zone Secondaries`" "; "$($_.ZoneName) = $out"}
share|improve this answer

Just to leave an alternative to Mathias's already great answer, here's a one-liner that works with any version of Powershell:

PS C:\> Get-WmiObject MicrosoftDNS_Zone -Namespace Root\MicrosoftDNS `
          -ComputerName DC01 | Where ZoneType -EQ 1 | `
          Select ContainerName, SecondaryServers

(ZoneType values for reference:

Edit: Duh, if using an older version of PS < 3, change the second element in the pipeline to

| Where { $_.ZoneType -EQ 1 } |

share|improve this answer
Simplicity at its best :-) – Mathias R. Jessen Apr 16 '14 at 0:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.