SkillPilotAI

PowerShell DnsServer module (1/5)

The DnsServer PowerShell module manages a Windows DNS server (zones, records, forwarders, policies) from the command line. This part covers the common parameters, forwarders, primary zones, directory partitions, query resolution policies and the Add- record cmdlets, with BIND as the hands-on equivalent.

241.1 Where it runs

  • Comes with the DNS Server role of Windows Server, or with the RSAT DNS Server Tools on a client PC.
  • Without the role/RSAT the module is simply not there: the read-only check below returned Count 0.
  • So the examples come from Microsoft Learn and the practical runs on BIND 9 in Docker (same as the dnscmd videos).
  • dnscmd is the old CLI; the DnsServer cmdlets are its modern PowerShell replacement.
PowerShell
Get-Command -Module DnsServer `  -ErrorAction SilentlyContinue |  Measure-Object
Output
PS C:\> Get-Command -Module DnsServer -ErrorAction SilentlyContinue | Measure-Object Count    : 0

241.2 Common parameters

ParameterWhat it does
-ComputerName server01Target a remote DNS server (on every cmdlet)
-CimSession Server01Run the cmdlet on a remote CIM session
-AsJobRun as a background job
-PassThruReturn the new object so the result is printed
-WhatIfShow what would happen, do not run
-ConfirmAsk for confirmation first
-ThrottleLimit 8Max parallel operations
  • Plus the normal PowerShell common parameters: -Verbose, -Debug, -ErrorAction, -WarningAction, -OutVariable, -ErrorVariable.

241.3 How a Windows DNS server resolves a query

Own zone, conditional forwarder, forwarder
  1. 1.Client asks dnssvr1 for a name

  2. 2.www.contoso.com: contoso.com is its primary zone -> answers directly

  3. 3.app.partner.com: conditional forwarder -> only Partner DNS 10.2.2.2

  4. 4.example.org: no zone, no condition -> server-level forwarder 8.8.8.8

  5. 5.Answer goes back to the client

Forwarder = all other names; conditional forwarder = one domain

241.4 Add-DnsServerForwarder and Add-DnsServerConditionalForwarderZone

PowerShell
Add-DnsServerForwarder `  -IPAddress 172.23.90.124 -PassThru Add-DnsServerConditionalForwarderZone `  -Name "contoso.com" -MasterServers `  2001:4898:7020:f100:458f:e6a2:fcaf:698c,  172.23.90.124 -PassThru
Output
ZoneName     ZoneType   IsAutoCreated  IsDsIntegrated  IsReverseLookupZone  IsSigned--------     --------   -------------  --------------  -------------------  --------contoso.com  Forwarder  False          False           False
  • Add-DnsServerForwarder: only -IPAddress is required; new IPs go to the END of the list, so add your preferred forwarder first.
  • Conditional forwarder: -Name and -MasterServers are required.
  • -ForwarderTimeout: seconds to wait for the master server.
  • -UseRecursion: try to resolve on its own after the forwarder fails.
  • -ReplicationScope Forest|Domain|Legacy|Custom (+ -DirectoryPartitionName): store and replicate it in Active Directory.
  • -LoadExisting: load an existing zone from the registry.

241.5 Lab: BIND forwarders and zone type forward

  • The module is Windows-only, so the lab uses BIND 9 on dnssvr1 (192.168.61.10).
  • options { forwarders; forward only; } = global forwarder (Add-DnsServerForwarder).
  • zone "corp.lab" { type forward; } = conditional forwarder.
Output
options {  recursion yes;  forwarders { 192.168.61.30; };  forward only;  dnssec-validation no;  allow-new-zones yes;};view "default" {  zone "corp.lab" {    type forward;    forward only;    forwarders { 192.168.61.20; };  };};
Output
$ dig @192.168.61.10 app.partner.lab A;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59497app.partner.lab.  3600  IN  A  192.168.61.60$ dig @192.168.61.10 www.example.com A;; ->>HEADER<<- opcode: QUERY, status: SERVFAIL, id: 57740$ dig @192.168.61.10 intranet.corp.lab A;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 38159intranet.corp.lab.  3600  IN  A  192.168.61.21$ dig @192.168.61.30 intranet.corp.lab A;; ->>HEADER<<- opcode: QUERY, status: REFUSED, id: 28279
  • www.example.com got SERVFAIL because the lab forwarder never goes to the internet.
  • Asking the global forwarder directly for intranet.corp.lab gave REFUSED: proof the answer came only via the conditional forwarder.

241.6 Add-DnsServerPrimaryZone and Add-DnsServerDirectoryPartition

PowerShell
Add-DnsServerPrimaryZone `  -Name "west01.contoso.com" `  -ReplicationScope "Forest" -PassThru Add-DnsServerPrimaryZone `  -Name "west02.contoso.com" `  -ZoneFile "west02.contoso.com.dns" Add-DnsServerPrimaryZone `  -NetworkID "10.1.0.0/24" `  -ReplicationScope "Forest" Add-DnsServerDirectoryPartition -Name "ADpart"
Output
ZoneName           ZoneType  IsAutoCreated  IsDsIntegrated  IsReverseLookupZone  IsSigned--------           --------  -------------  --------------  -------------------  --------1.10.in-addr.arpa  Primary   False          True            True                 False
Zone kindKey parameters
AD-integrated forward zone-Name + -ReplicationScope Forest|Domain|Legacy|Custom
File-backed zone-Name + -ZoneFile west02.contoso.com.dns
Reverse lookup zone-NetworkId 10.1.0.0/24
Custom AD partition-ReplicationScope Custom + -DirectoryPartitionName
  • -DynamicUpdate None|Secure|NonsecureAndSecure; Secure works only in AD-integrated zones.
  • Other options: -ResponsiblePerson, -LoadExisting, -VirtualizationInstance.
  • Add-DnsServerDirectoryPartition creates a DNS application partition; -Type Domain|Forest|AllDomains. Forest and domain partitions are created automatically at DNS install (dnscmd: /createdirectorypartition).
  • BIND equivalent: rndc addzone on a running server (needs allow-new-zones yes).
Terminal
rndc addzone west02.contoso.com in default \  '{ type primary;     file "/var/bind/west02.contoso.com.db";     allow-update { key upd-key; }; };'rndc zonestatus west02.contoso.com in default
Output
name: west02.contoso.comtype: primaryfiles: /var/bind/west02.contoso.com.dbserial: 2026110901dynamic: yes$ grep west02 /var/log/named/named.log17:01:44.733 zone west02.contoso.com/IN/default: loaded serial 202611090117:01:44.733 added zone west02.contoso.com in view default via addzone

241.7 Query resolution policy: same name, different answer

Traffic management with a policy
  1. 1.Add-DnsServerClientSubnet: NorthAmericaSubnet = 172.21.33.0/24

  2. 2.Add-DnsServerZoneScope: NorthAmericaZoneScope inside contoso.com

  3. 3.Add career A 172.21.21.21 into that zone scope

  4. 4.Add-DnsServerQueryResolutionPolicy links subnet -> scope

  5. 5.NA client asks career.contoso.com -> 172.21.21.21

  6. 6.Europe client asks the same name -> 172.17.97.97 (its own scope)

PowerShell
Add-DnsServerClientSubnet `  -Name "NorthAmericaSubnet" `  -IPv4Subnet "172.21.33.0/24" -PassThruAdd-DnsServerZoneScope `  -ZoneName "Contoso.com" `  -Name "NorthAmericaZoneScope" -PassThruAdd-DnsServerResourceRecord `  -ZoneName "Contoso.com" -A -Name "career" `  -IPv4Address "172.21.21.21" `  -ZoneScope "NorthAmericaZoneScope" -PassThruAdd-DnsServerQueryResolutionPolicy `  -Name "NorthAmericaPolicy" -Action ALLOW `  -ClientSubnet "eq,NorthAmericaSubnet" `  -ZoneScope "NorthAmericaZoneScope,1" `  -ZoneName "Contoso.com" -PassThru
Output
Action          : AllowAppliesOn       : QueryProcessingCondition       : AndIsEnabled       : TrueLevel           : ZoneName            : NorthAmericaPolicyProcessingOrder : 1ZoneName        : contoso.com
  • Every policy = criteria + action + scopes.
  • Criteria (written "EQ,value" or "NE,value"): -ClientSubnet, -Fqdn, -QType, -ServerInterfaceIP, -InternetProtocol, -TransportProtocol, -TimeOfDay.
  • -Action ALLOW answers; DENY replies SERVFAIL; IGNORE sends no reply at all.
  • -Condition AND|OR combines criteria; -ProcessingOrder: smaller number is checked first.
  • -ZoneScope "scope,weight;..." can split answers by weight; -ApplyOnRecursion + -RecursionScope apply the policy to recursion.
  • Add-DnsServerRecursionScope: own forwarders + EnableRecursion per scope; the default scope "." cannot be added or removed.
Output
PS C:\> Add-DnsServerRecursionScope -Name "ScopeInternal" -Forwarder 10.0.0.1,172.22.0.1 -EnableRecursion $True -PassThruName           Forwarder               EnableRecursion----           ---------               ---------------ScopeInternal  {10.0.0.1, 172.22.0.1}  True
  • BIND lab: open-source BIND has no Windows-style policies; the closest equivalent is a view with match-clients.
Output
acl "branch-subnet" { 192.168.61.40/32; };view "branch" {  match-clients { branch-subnet; };  zone "contoso.com" { type primary;    file "/var/bind/branch/contoso.com.db";  };};view "default" {  match-clients { any; };  zone "contoso.com" { type primary;    file "/var/bind/default/contoso.com.db";  };};
Output
$ dig -b 192.168.61.30 @192.168.61.10 career.contoso.com A +short192.168.61.100$ dig -b 192.168.61.40 @192.168.61.10 career.contoso.com A +short192.168.61.140

241.8 Add-DnsServerResourceRecord and the per-type cmdlets

  • Generic cmdlet: -ZoneName -Name + one of 21 type switches (-A -AAAA -CName -MX -Ptr -Srv -Txt -NS -DName ... -X25).
  • Each type has its own data parameters: -IPv4Address, -HostNameAlias, -MailExchange + -Preference, -Priority -Weight -Port (SRV), -DescriptiveText...
  • For all types: -TimeToLive 01:00:00, -AgeRecord (timestamp for scavenging), -AllowUpdateAny, -ZoneScope.
  • Short cmdlets exist for common types: Add-DnsServerResourceRecordA / AAAA / CName / DS.
  • -CreatePtr (A, AAAA) also creates the PTR record in the reverse zone.
  • -AllowUpdateAny: any authenticated user may update a record with this name.
PowerShell
Add-DnsServerResourceRecordA -Name "host23" `  -ZoneName "contoso.com" -AllowUpdateAny `  -IPv4Address "172.18.99.23" `  -TimeToLive 01:00:00Add-DnsServerResourceRecordAAAA `  -Name "host24" -ZoneName "contoso.com" `  -AllowUpdateAny -IPv6Address "3ffe::1" `  -TimeToLive 01:00:00Add-DnsServerResourceRecordCName `  -Name "labsrv1" `  -HostNameAlias "srv1.lab.contoso.com" `  -ZoneName "contoso.com" $b = Get-DnsServerResourceRecord `  -RRType DS -ZoneName "contoso.com" `  -computerName "Server1"$b[0].RecordData |  Add-DnsServerResourceRecordDS `  -ZoneName "contoso.com" -Name "west02" `  -computerName "Server2"
  • DS (Delegation Signer) keeps the digest of the child zone's DNSSEC key in the parent zone: the chain of trust.
  • DS parameters: -KeyTag, -CryptoAlgorithm (RsaSha256, ECDsaP256Sha256...), -DigestType Sha1|Sha256|Sha384, -Digest. -AgeRecord is not relevant for DS.
Lab: dynamic update with nsupdate + TSIG
  1. 1.Client runs nsupdate without a key -> update denied (REFUSED)

  2. 2.Same as secure dynamic update on Windows

  3. 3.nsupdate -k /root/upd.key signs the update with TSIG

  4. 4.Server adds host23 A, host24 AAAA, labsrv1 CNAME

  5. 5.named.log records the key name upd-key

Output
server 192.168.61.10zone west02.contoso.comupdate add host23.west02.contoso.com 3600 A 192.168.61.23update add host24.west02.contoso.com 3600 AAAA fd00:61::24update add labsrv1.west02.contoso.com 3600 CNAME host23.west02.contoso.com.send
Output
17:01:51.220 client @0x7e0908581140 192.168.61.30#44510: view default: update 'west02.contoso.com/IN' denied17:01:52.719 client @0x7e0908581140 192.168.61.30#37039/key upd-key: view default: updating zone 'west02.contoso.com/IN': adding an RR at 'host23.west02.contoso.com' A 192.168.61.2317:01:52.723 client @0x7e0908581140 192.168.61.30#37039/key upd-key: view default: updating zone 'west02.contoso.com/IN': adding an RR at 'labsrv1.west02.contoso.com' CNAME host23.west02.contoso.com.

241.9 Common mistakes

  • Thinking a forwarder and a conditional forwarder are the same: forwarder = all unknown names, conditional = one domain.
  • Adding the preferred forwarder last: new forwarders go to the end of the list.
  • Expecting -DynamicUpdate Secure on a file-backed zone: it needs an AD-integrated zone.
  • Forgetting -PassThru and then thinking nothing happened (no output by default).

241.10 Interview tips

  • One name, different IPs per user: Add-DnsServerClientSubnet + Add-DnsServerZoneScope (+ records) + Add-DnsServerQueryResolutionPolicy; in BIND, views + match-clients.
  • Only partner.com via the partner DNS: Add-DnsServerConditionalForwarderZone -Name partner.com -MasterServers <IP>; BIND: zone type forward.
  • Policy actions: ALLOW answers, DENY = SERVFAIL, IGNORE = silent drop.
  • DS record in the parent zone builds the DNSSEC chain of trust to the child zone.