How to easily manage DNS Zone using PowerShell?

Hello, PowerShell enthusiast today we will understand the interesting concept of DNS Zone and how to manage them using PowerShell. If you are already working in Windows server-related environment then you should be aware of the terms Primary, Secondary, and Stub zone in DNS. Let’s start our exciting journey for today and dwell on DNS.

What are Primary, Secondary, and Stub Zone in DNS?

Primary Zone:

As the name suggests it is a primary and important zone with a read-write portion of the DNS Namespace. Whenever a server has a DNS role has a primary zone hosted in that case the server then the server is an Authoritative server. In general, the DNS server created first in an environment will be an Authoritative DNS server.

Secondary Zone:

When it comes to Secondary Zone it can be termed as a copy-paste zone but only have read-only capabilities not write capabilities.

It is a friend of the Primary DNS zone who helps each other i.e. it shares the load on the Primary DNS zone with preventing a single point of failure.

Stub Zone:

Let me put it forward this way, there is a company X that hired a company Y, now they need to get merged but the domain Y.com won’t change but what you can do is you will be able to ping Y.com from X.com because of Stub zone. A stub zone is used to resolve the name between 2 different DNS namespaces.

Also, it contains a copy of the required resource records that is necessary to identify the authoritative DNS server.

 

Managing DNS Primary zone with PowerShell

#1 Creating Primary Zone

ZONE_NAME – Provide the Zone Name which needs to be created 

SCOPE – Replace scope with the following value: Forest, Domain, Legacy, or Custom

UPDATE_TYPE – Replace scope with the following value: None, Secure, or NonesecureAndSecure

				
					Add-DnsServerPrimaryZone -Name "Zone_Name" -ReplicationScope "Scope" -DynamicUpdate "update_type" –PassThru
				
			

#2 Removing Primary Zone

The below command is self-explanatory as it will remove the primary zone which is present in your domain.

				
					Remove-DnsServerZone -Name "Zone_Name" -ComputerName "DNS_server_Name"
				
			

Find more DNS related PowerShell scripts from here, DNS Scripts

Managing DNS Secondary zone with PowerShell

#1 Creating Secondary Zone

ZONE_NAME – Provide the name of the actual zone

ZONE_FILENAME – Replace with the same zone name, just append “.dns” at the end

MASTER_IP – Provide Master IP Address (Primary DNS server)

				
					Add-DnsServerSecondaryZone -Name "Zone_Name" -ZoneFile "Zone_FileName" -MasterServers "Master_IP"
				
			

#Removing Secondary Zone

				
					Remove-DnsServerZone -Name "Zone_Name" -ComputerName "DNS_server_Name"
				
			

Managing Stub Zone with Powershell

#1 Creating a Sub Zone

ZONE_NAME – Provide the name of the actual zone

MASTER_IP – Provide Master IP Address

SCOPE – values depending on the replication scope that you want to set: “Forest”, “Domain”, “Legacy”, or “Custom”

				
					Add-"DnsServerStubZone -Name ZONE_NAME" -MasterServers "MASTER_IP" -ReplicationScope "SCOPE"
				
			

#Removing Stub Zone

				
					Remove-DnsServerZone -Name "Zone_Name" -ComputerName "DNS_server_Name"
				
			

Conclusion

I hope you have liked the post How to easily manage DNS Zone using PowerShell? and will implement this whenever it is required. Things you should always remember is to try with one zone so that it will be easy for you to make changes. Let me know if you want a blog post on some other script that might amaze you.

We are working continuously to provide you with the better and the best scripts daily. We will publish weekly hence don’t forget to subscribe to our newsletter. 

Related Posts

Leave a Reply

Please disable your adblocker or whitelist this site!