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,

[pre]

$DNSServer = “xxx.xxx.xxxxx”

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

$All | Sort-Object HostName

[/pre]

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.

Example:

DNS
(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.

https://techibee.com/active-directory/powershell-get-all-domains-and-domain-controllers-in-whole-forest/2868

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 in-addr.arpa because we probably don’t care about reverse DNS for this question).

$server = "YOURDNSSERVER"
$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        10.0.0.2

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

In the Windows DNS Manager you would see a folder icon under the zone contoso.com with the name subdomain. Inside that folder would be an A record pointing to 10.0.0.2. 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.