How to Manage DNS Zones With PowerShell

choubertsprojects

The Best WordPress plugins!

1. WP Reset

2. WP 301 Redirects

3. WP Force SSL

When you are managing hundreds of DNS zones, there is a lot to keep track of. One way that PowerShell can help with this issue is via the ADsPath module. This will allow you to manage your DNS records in bulk using functions such as New-DnsServerZone and Remove-DnsServerZone.

The “get-dnsserverresourcerecord” is a PowerShell cmdlet that allows you to manage DNS zones. The cmdlet has been around for a while, but it’s still worth knowing how to use it.

How to Manage DNS Zones With PowerShell

You’re probably wasting a lot of time if you use the DNS MMC snap-in to make modifications to your Microsoft DNS servers. Learn how to create DNS zones and control them completely using PowerShell!

Why? Because PowerShell can build, change, and delete any DNS object that can be created, modified, or removed from the MMC! When you handle DNS using PowerShell, you can not only control things from the command line, but you can also put those commands into a script to automate a variety of time-consuming chores.

To keep this post concise, we’ll just cover controlling DNS zones using PowerShell, while it’s also feasible to manage other DNS objects such as records and the server itself.

Prerequisites

Before we go any further, there are a few things you should be aware of. First, I’m assuming you have authority to use PowerShell to read, edit, and delete DNS zones on your Windows servers.

Second, I’ll show you how to use DNS servers in an Active Directory domain using AD-integrated zones to demonstrate a few ideas. PowerShell can still manage zones and records outside of Active Directory, but the results may not be as good as what I’ll show you here.

Finally, make sure you have a version of the Remote Server Administration Tools (RSAT) that is relevant to your operating system loaded on your client.

How to Connect to Active Directory and Install the Active Directory Module

The DNSServer Module is being tested.

Now that we’ve got that out of the way, let’s get started by making sure the DNSServer module is installed. I’ll use the Get-Module cmdlet to do this.

PS> Get-Module DnsServer -ListAvailable Directory: C:Windowssystem32WindowsPowerShellv1.0Modules ModuleType Version Name ExportedCommands ———- ——- —- —————- Manifest 2.0.0.0 DnsServer {Add-DnsServerConditionalForwarderZone, Add-DnsServerDirectoryPartition, Add-DnsServerForwarder, Add-DnsServerPrimaryZone…} Great! It looks like our module is downloaded and we have some available commands. Let’s now see what commands we have to work with DNS zones. PS> Get-Command -Module DnsServer -Noun *Zone* CommandType Name Version Source ———– —- ——- —— Function Add-DnsServerConditionalForwarderZone 2.0.0.0 DnsServer Function Add-DnsServerPrimaryZone 2.0.0.0 DnsServer — SNIP —

Adding a DNS Zone using PowerShell

First, let’s use PowerShell to establish a zone. We’ll utilize the Add-DnsServerPrimaryZone method to do this. Using two parameters is the easiest method to do this. Name and ReplicationScope are the parameters in question. However, since I’m running this command on a remote computer, I’ll additionally use the ComputerName option in our example.

PS> Add-DnsServerPrimaryZone -Name testzone.mylab.local -ComputerName DC -ReplicationScope Forest

My domain is mylab.local, and my zone is testzone, as you can see above. Because my DNS server is a DC, I supply that for the ComputerName parameter, and because this server is part of my domain, I also have to select the ReplicationScope, so I’ve opted to replicate this zone across all DNS servers in my Active Directory forest.

Verifying the DNS Zones that Have Been Created

I can then use the Get-DnsServerZone command to verify that this zone was created. I could use the Name argument, but if I want to show you all of my zones, I’ll simply use Get-DnsServerZone.

PS> Get-DnsServerZone -ComputerName DC ZoneName ZoneType IsAutoCreated IsDsIntegrated IsReverseLookupZone IsSigned ——– ——– ————- ————– ——————- ——– _msdcs.mylab.local Primary False True False False 0.in-addr.arpa Primary True False True False 127.in-addr.arpa Primary True False True False 255.in-addr.arpa Primary True False True False mylab.local Primary False True False False testzone.mylab.local Primary False True False False TrustAnchors Primary False True False F

Using PowerShell to remove the DNS Zone

I’ll then delete it to make sure we’ve gone through the whole lifespan of a DNS zone.

PS> Remove-DnsServerZone -Name testzone.mylab.local -ComputerName DC -Confirm

Do you wish to continue? This will also erase all of the records in the zone, and the server will no longer host the zone.

[Y] Yes [N] No [S] Suspend [?] Help (default is “Y”): y PS> Get-DnsServerZone -ComputerName DC ZoneName ZoneType IsAutoCreated IsDsIntegrated IsReverseLookupZone IsSigned ——– ——– ————- ————– ——————- ——– _msdcs.mylab.local Primary False True False False 0.in-addr.arpa Primary True False True False 127.in-addr.arpa Primary True False True False 255.in-addr.arpa Primary True False True False mylab.local Primary False True False False TrustAnchors Primary False True False

Now that you’ve learnt about DNS zones, why not go on to the next logical step and learn about DNS records in this extensive, step-by-step lesson on DNS record management.

Summary

There’s a lot more you can do with DNS zones with PowerShell. I recommend that you go via Get-Command -Module DnsServer -Noun Zone and look at all of the commands available. This command displays a list of all commands in the DnsServer module that have the word ‘Zone’ in their name. You’ll find that the command names are self-explanatory, and if you need more information, use Get-Help to look up the help for each command.

The “add-dnsserverprimaryzone” is a PowerShell cmdlet that allows users to manage their DNS zones. This cmdlet can be used to add, remove, or change the primary zone of an existing DNS server.

Related Tags

  • export all dns zones and records with powershell
  • get-dnsserverzone
  • powershell script to update dns records
  • powershell find stale dns records
  • powershell add name server to zone

Table of Content