Cmdlet/Code to show Secondary Zones under Primary Zones in DNS

Is there a reason why Secondary Zones do not show under Primary Zone listings in DNS/cmdlet (example code down below). I am trying not to hard code if I don’t have too. Would like to provide the DNS servers, which I can get a listing of the primary zone and the records below them. Just can’t get a list of Secondary Zones below the Primary Zones, which I can clearly see in DNS. This doesn’t matter if I run the code on the server or remote. Searching google, haven’t found a solution yet…figured I would ask here if anyone else has tried to pull the following information. Cheers,


$DNSServer = “”

$All = @()
$Zones = @(Get-DnsServerZone -ComputerName $DNSServer -Name
ForEach ($Zone in $Zones) {
$Results = $Zone | Get-DnsServerResourceRecord -ComputerName $DNSServer
$All += $Results

$All | Sort-Object HostName


I cannot check at the moment but the doc states for the parameter -Name “If you do not specify one or more names, the cmdlet gets all the zones for the server.”. If this lists the subdomains as well you could use it and filter the desired domains afterwards.

The -Name parameter works when drilling down to the primary domain, but there doesn’t seem to be a parameter/value that drills down or can pipe out the subdomains under the primary domain.



Updated the question and text to be more clear I want to get the zone name information and not initially about domains.


(DNS Server)
Forward Lookup Zones
Zone Name (Domain Name)
Zone Name (Domain Name) << - want to grab this name, not the records.


Give these resources a shot.

Forest and Domain Information

PowerShell Version 1.0 script to determine functional level of the Active Directory forest and all domains in the forest. Also finds all FSMO role holders, all sites, and and all Global Catalog servers in the forest.

I’m still looking into this, but it seems that cmdlet : Get-DnsServerResourceRecord will show duplicate records when a sub-domain matches the zone. Reading on a few sites, looks like a bug. Once post an update tomorrow, hopefully will have a solution. Appreciate the feedback from people so far.

Hi Adam,
I’m not entirely clear on your question. If you mean secondary zone like a non-authoritative zone (only pulling zone updates from a primary zone on another server) it should show up just like any other zone on the server, and display the same way described in the rest of this post.

If you are talking about sub-domains they do show up with Get-DnsServerResourceRecord. But they will look like [host].[subdomain] in the list, and the FQDN would be [host].[subdomain].[zone].

This script will retrieve all zones from a server (and ignore because we probably don’t care about reverse DNS for this question).

$dnsserver = Get-DnsServer -ComputerName $server

foreach ($zone in $dnsserver.ServerZone)
    if (-Not ($zone.IsReverseLookupZone))
        write-host "`n---------------------------`n"
        write-host $zone.ZoneName
        Get-DnsServerResourceRecord -Computername $server -ZoneName $zone.ZoneName
        write-host "`n---------------------------`n"

How when it comes to sub-domains displayed in the list they will look like this:

test.subdomain               A          1          0                    01:00:00

In this case test is the host name and subdomain is the sub-domain. If the zone name were the FQDN here would be

In the Windows DNS Manager you would see a folder icon under the zone with the name subdomain. Inside that folder would be an A record pointing to Windows DNS manager displays zones in way that can be confusing when compared to a bind zone file format - which is similar to what Get-DnsServerResourceRecord will output.

If I am completely misunderstanding your question, I apologize. Hopefully this helpful in some way.