PowerShell DnsServer module (3/5)
The Get- cmdlets of the DnsServer module read a Windows DNS server: its configuration, cache, recursion, statistics, policies, zones, records and DNSSEC state. This part also covers the Import, Invoke and Remove cmdlets, with rndc and dig on BIND 9 as the lab equivalent (the module is not installed on the office PC: Count 0).
243.1 Why is it used?
- Troubleshooting: see what the server is really configured to do before changing anything.
- Audit and backup: Get-DnsServer | Export-Clixml saves the whole config as XML.
- Health: statistics show failures (SERVFAIL), cache limits and recursion state.
- Get- cmdlets run remotely with -ComputerName and normally change nothing on the server.
243.2 How it works
- Step 1
1.Client 10.0.0.50 asks dnssvr1 for www.example.org
- Step 2
2.dnssvr1 forwards to the forwarder 8.8.8.8
- Step 3
3.Answer is cached until its TTL ends, then sent to the client
- Step 4
4.Admin PC 10.0.0.5 runs Get-DnsServerCache against dnssvr1
- Step 5
5.Server returns one object: MaxTTL, MaxKBSize ...
- Step 6
6.Read-only: nothing changes on the server
243.3 Server-level settings
PowerShell
Get-DnsServer -ComputerName "10.255.255.254"Get-DnsServer | Export-Clixml ` -Path "c:\config\DnsServerConfig.xml" Get-DnsServerSetting -AllOutput
MajorVersion : 6BuildNumber : 8230EnableDnsSec : TrueAllowUpdate : TrueRoundRobin : TrueLocalNetPriority : TrueMaximumUdpPacketSize : 4000SocketPoolSize : 2500SendPort : RandomListeningIPAddress : {172.23.90.136}| Cmdlet | Returns |
|---|---|
| Get-DnsServerCache | Cache SETTINGS (MaxTTL 1 day, MaxNegativeTTL 15 min), not the cached records |
| Get-DnsServerRecursion | Recursion on/off + timeouts (docs: Enable False) |
| Get-DnsServerDsSetting | AD settings: PollingInterval 180 s, TombstoneInterval 14 days |
| Get-DnsServerForwarder | Forwarders list |
| Get-DnsServerEDns | EDNS settings |
| Get-DnsServerDiagnostics | Logging (docs: Queries False, EventLogLevel 4) |
| Get-DnsServerScavenging | Aging/scavenging settings |
| Get-DnsServerGlobalNameZone / GlobalQueryBlockList | Single-label names / names never answered |
| Get-DnsServerEncryptionProtocol | DNS over HTTPS settings (Windows Server 2025+) |
| Get-DnsServerRootHint | Root servers list |
PowerShell
Get-DnsServerEncryptionProtocolGet-DnsServerEncryptionProtocol ` -ComputerName "dns1.contoso.com"Get-DnsServerRootHint | Where-Object { $_.NameServer.RecordData.NameServer -eq "H.Root-Servers.net."}Output
PS C:\> Get-DnsServerEncryptionProtocol EnableDoh : TrueUriTemplate : https://dnsserver.example.net/dns-query PS C:\> Get-DnsServerEncryptionProtocol -ComputerName "dns1.contoso.com" EnableDoh : FalseUriTemplate :243.4 Statistics and RRL
- Get-DnsServerStatistics: without -ZoneName = whole server; with -ZoneName = that zone only.
- Careful: -Clear with -ZoneName CLEARS that zone's statistics, so a Get- can change something.
- Get-DnsServerResponseRateLimiting shows RRL settings; pipe it to Set- to copy RRL from server1 to server2.
- Get-DnsServerResponseRateLimitingExceptionlist -Name "SafeList1" reads the exception lists.
PowerShell
Get-DnsServerRRL -ComputerName "server1" | Set-DnsServerRRL ` -ComputerName "server2" -force243.5 Lab: rndc status, named-checkconf, dumpdb, stats
- Lab: dnssvr1 192.168.63.10 (BIND 9.18) and a client 192.168.63.20 that is also the forwarder.
- rndc status = Get-DnsServer idea; named-checkconf -p = Get-DnsServerForwarder/Recursion/EDns idea.
- rndc dumpdb -cache dumps the cached RECORDS (Windows Get-DnsServerCache shows only settings).
- rndc stats = Get-DnsServerStatistics idea, written to named.stats.
Terminal
rndc statusnamed-checkconf -p | grep -E -A1 '^\s+forwarders' | grep -v secretdig @192.168.63.10 app.partner.lab Arndc dumpdb -cachegrep -E '^; (Start|Cache)|partner.lab|^app' \ /var/bind/named_dump.dbrndc statsgrep -A10 '++ Name Server Statistics ++' \ /var/bind/named.statsOutput
$ rndc statusversion: BIND 9.18.49 (Extended Support Version) <id:cd4a53b>boot time: Mon, 09 Nov 2026 17:19:36 GMTconfiguration file: /etc/bind/named.confnumber of zones: 3 (0 automatic)query logging is OFFrecursive clients: 0/900/1000tcp clients: 0/150server is up and running$ rndc dumpdb -cache && grep -E '^; (Start|Cache)|partner.lab|^app' /var/bind/named_dump.db; Start view _default; Cache dump of view '_default' (cache _default)app.partner.lab. 3593 IN A 192.168.63.60$ dig @192.168.63.10 www.example.com A;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 19887$ grep -A10 '++ Name Server Statistics ++' /var/bind/named.stats++ Name Server Statistics ++ 4 IPv4 requests received 4 requests with EDNS(0) received 4 responses sent 3 queries resulted in successful answer 1 queries resulted in authoritative answer 2 queries resulted in non authoritative answer 1 queries resulted in SERVFAIL 2 queries caused recursion- named-checkconf -p showed recursion yes, forwarder 192.168.63.20, edns-udp-size 1232 and max-cache-size in bytes (33554432 = 32m).
- www.example.com gave SERVFAIL because the lab forwarder never goes to the internet: that is the 1 SERVFAIL in the stats.
243.6 Policies, scopes and partitions
PowerShell
Get-DnsServerClientSubnet | Format-ListGet-DnsServerQueryResolutionPolicy ` -Name "NorthAmericaPolicy" ` -ZoneName "contoso.com" | Format-List *Get-DnsServerRecursionScopeGet-DnsServerZoneScope -ZoneName "contoso.com"Get-DnsServerDirectoryPartitionOutput
Name Forwarder EnableRecursion---- --------- ---------------. TruescopeInternal {10.0.0.1, 172.22.0.1} True server.DirectoryPartitionName State Flags ZoneCount----------------------------- ----- ----- ---------DomainDnsZones.mytest.cont... 0(DNS_DP_OKAY) Enlisted Auto Domain 3ForestDnsZones.mytest.cont... 0(DNS_DP_OKAY) Enlisted Auto Forest 2- Query resolution / zone transfer policy: give -ZoneName for zone-level policies, leave it out for server-level ones.
- Get-DnsServerZoneScope needs -ZoneName; Get-DnsServerVirtualizationInstance without -Name lists all (default ".").
- Get-DnsServerDirectoryPartition -Custom lists only custom partitions.
243.7 Zones, records and DNSSEC
- Get-DnsServerZone: no name = all zones.
- Get-DnsServerResourceRecord -ZoneName (required) -Name Host03 -RRType A|MX|NS... ; -Node = only records at that node.
- Get-DnsServerZoneAging: primary zones only. Get-DnsServerZoneDelegation -Name <parent> lists child delegations.
- Get-DnsServerDnsSecZoneSetting, Get-DnsServerSigningKey, Get-DnsServerTrustAnchor, Get-DnsServerTrustPoint read the DNSSEC state.
Output
PS C:\> Get-DnsServerDnsSecZoneSetting -ZoneName "western.contoso.com"ZoneName : western.contoso.comIsKeyMasterServer : TrueKeyMasterServer : rootKeyMasterStatus : OnlineDenialOfExistence : NSec3NSec3HashAlgorithm : RsaSha1NSec3Iterations : 50DnsKeyRecordSetTTL : 01:00:00DSRecordGenerationAlgorithm : {Sha1, Sha256}EnableRfc5011KeyRollover : FalsePowerShell
Invoke-DnsServerZoneSign ` -ZoneName "contoso.com" -SignWithDefaultInvoke-DnsServerZoneUnsign -ZoneName "contoso.com" -ForceGet-DnsServerSigningKey ` -ZoneName "DNSServer06.Contoso.com" | Invoke-DnsServerSigningKeyRollover -ForceImport-DnsServerResourceRecordDS ` -ZoneName "contoso.com" -DSSetFile ` "c:\windows\system32\dns\dsset-finance..."- -SignWithDefault creates one ZSK and one KSK; -DoResign re-signs an already signed zone.
- Import-DnsServerTrustAnchor takes a -KeySetFile or -DSSetFile.
- BIND lab: dnssec-policy default (same idea as SignWithDefault) gave one CSK, ECDSAP256SHA256, key tag 57938.
Output
$ dig @192.168.63.10 www.contoso.lab A;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 5763;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1; EDNS: version: 0, flags:; udp: 1232www.contoso.lab. 3600 IN A 192.168.63.80$ dig @192.168.63.10 www.contoso.lab A +dnssec +noall +answer +multilinewww.contoso.lab. 3600 IN A 192.168.63.80www.contoso.lab. 3600 IN RRSIG A 13 3 3600 ( 20261123110619 20261109161936 57938 contoso.lab. VcsWktnPJYhWZ9Txu9xUkOf110rH3pTP1Jsk5jtnf8xp neZGVbHW15VBbsQPF6Z0RIVoOtb1ZCCsW9DKIFckXA== )243.8 Import, Register and Remove
PowerShell
Import-DnsServerRootHint ` -NameServer "172.23.90.136" -PassThruRegister-DnsServerDirectoryPartition ` -Name "hr.dept.contoso.com"Remove-DnsServerForwarder ` -IPAddress 10.0.0.8 -PassThruRemove-DnsServerClientSubnet ` -Name AsiaSubnet -PassThru -ForceRemove-DnsServerQueryResolutionPolicy ` -Name "LBPolicy" -ZoneName "contoso.com"Remove-DnsServerResourceRecord ` -ZoneName "contoso.com" -RRType "A" ` -Name "Host01" -RecordData "10.17.1.41"Output
ConfirmRemoving the zone level policy LBPolicy from zone contoso.com on the DNS server SERVER01-T10. Do you want to continue?[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y- Import-DnsServerRootHint copies root hints from another server and does not overwrite existing ones.
- Register-DnsServerDirectoryPartition enlists the server in an application partition's replication scope.
- -Force removes without a prompt; without -Force a zone-level policy removal asks to Confirm.
- Remove-DnsServerResourceRecord without -RecordData deletes ALL records of that name and type.
- rndc tsig-list in the lab shows only key names (upd-key, local-ddns), never secrets.
243.9 Common mistakes
- Assuming every Get- is read-only: Get-DnsServerStatistics -ZoneName -Clear clears statistics.
- Expecting Get-DnsServerCache to list cached records: it shows only the cache settings.
- Leaving out -RecordData in Remove-DnsServerResourceRecord and wiping every record of that name.
- Using -Force on Remove- without checking with the matching Get- first.
243.10 Interview tips
- Wrong/slow answers: check the path (Get-DnsServerForwarder, Get-DnsServerRecursion), then the record (Get-DnsServerResourceRecord) and cache (Get-DnsServerCache), then failures (Get-DnsServerStatistics).
- How long are answers cached at most? Get-DnsServerCache -> MaxTTL (docs: 1.00:00:00); BIND: max-cache-ttl + rndc dumpdb.
- Back up a DNS server config: Get-DnsServer | Export-Clixml.
- aa flag in dig = authoritative answer from the zone's own server.