8 Best Powershell scripts to manage DNS

Another main part of Active Directory is DNS. If you are a windows server administrator you are well aware how it works but managing and automating with Powershell is somewhat is difficult when it comes to create one without knowing what the command will actually do.

DNS plays a crucial role in an organization which really needs a sneak peek so that it works well without any issue.In our field creating a DNS record for a server or workstation looks easy by GUI but when it comes to create some n number of DNS record at a time it becomes difficult. From creating the record and pointing it to correct IP becomes challenging. But I have accepted the challenge and created few relatable scripts which I have optimized to run without ay clutters. If you like this section then you will surely like the DHCP powershell scripts as well as my repository of powershell scripts.

Well what starts good ends good and below are some examples of it. From restoring DNS server to creating zones in the DNS I have done it all. Below are some books which you can refer if you are opting to learn about DNS or powershell. Below are my best available DNS Powershell scripts you don’t want to miss.

Useful Powershell commands for DNS

Add DNS Forwarder

				
					Add-DnsServerForwarder -IPAddress IP -PassThru
				
			

Add Root Hint server

				
					Add-DnsServerRootHint -NameServer "domain.com" -IPAddress IP
				
			

Get DNS server configuration

				
					Get-DnsServer -ComputerName "IP"
				
			

Get DNS server forwarder settings

				
					Get-DnsServerForwarder
				
			

Remove forwarder from a DNS server

				
					Remove-DnsServerForwarder -IPAddress IP -PassThru
				
			

Set DNS server configuration

				
					Get-DnsServer -CimSession IP | Set-DnsServer
				
			

Clear DNS Cache

				
					Clear-DnsServerCache -ComputerName "Name of server" -Force
				
			

Restore DNS Zone

Creation of zone is made easier in Powershell with a simple command no need to go the dnsmgmt.msc to create a new required zone

How it works

The script will search for the backup in the backup folder and search for the zone specified which ca be restored.

Probable outcome

If you have provided everything correct the DNS zone should be back with th latest backup.

Download

You can download the script from below.

Create Primary/Secondary/Stub zone

Deleted DNS zone mistakenly, no worries if you have a backup of of the dns zone. It is a quite handy script to restore the DNS zone.

How it works

Just provide the zone IP which will in turn will create secondary zone in the required server.

Problem outcome

A primary/secondary/stub zone will be created on the required server.

Download

You can download the script from below.

Create DNS Forwarder

Creation of DNS forwarder is very quick and easy in Powershell. Just a one line code to slip away with clickings.

How it works

Provide the forwarder IP in bulk or a single IP and run the script it should create the DNS forwarder but make sure you provide correct IP’s.

Probable Outcome

The script will create DNS forwarder and this should be pinging and request should be redirected to the forwarder.

Download

You can download the script from below.

Modify DNS records

Creation of DNS forwarder is very quick and easy in Powershell. Just a one line code to slip away with clickings.

How it works

Provide the forwarder IP in bulk or a single IP and run the script it should create the DNS forwarder but make sure you provide correct IP’s.

Probable Outcome

The script will create DNS forwarder and this should be pinging and request should be redirected to the forwarder.

Download

You can download the script from below.

Create Multiple DNS Record

Ever faced the challenge of searching for the DNS record to change the IP, well Powershell has made it so easy and reliable this script is a better example of it.

How it works

It will change the IP of a hostname to the required IP. Just provide the correct details and check how it works. 

Probable Outcome

If everything goes correct the hostname IP should be replaced by the new provided IP.

Download

You can download the script from below.

Check FQDN of multiple host

Consider a situation where you are asked to provide FQDN of multiple host in your environment but you don’t know how many of them are workgroup servers “TROUBLE” , well I have created a script just for this moment so that rather checking one by one by nslookup we can actually create a script for the same. A FQDN looks like hostname.xyz.com .

How it works

It will use nslookup and provide the FQDN of the multiple servers within short span of time.

Probable Outcome

You will be getting the FQDN of the host if it exist in your environment if it doesn’t then yes you have to check if this is a workgroup server or you have a typo in the list. Incase you have any doubt to reach out to me if you face any issue or let me know if video demonstration is required for this. You can directly reach me out in Facebook or Gmail both addresses are in the footer.

Download

You can download the script from below.

Book for DNS
Powershell Books
close
Powershell Blogs

Sign up to receive awesome content from PowershellGuru