PowerShell for DNS Administration: 15 Essential Commands with Examples

Managing DNS (Domain Name System) using PowerShell is a powerful way to automate and streamline your DNS administration tasks, especially in enterprise Windows Server environments. PowerShell provides full control over DNS zones, records, and settings, enabling sysadmins to execute complex operations with simple commands. In this blog, we will explore 15 practical PowerShell commands that every Windows DNS administrator should know.

1. List All DNS Zones

Get-DnsServerZone

Use this command to retrieve a list of all DNS zones hosted on your DNS server.

2. Create a New Forward Lookup Zone

Add-DnsServerPrimaryZone -Name "example.com" -ZoneFile "example.com.dns"

This command creates a new forward lookup zone called “example.com” with an associated zone file.

3. Create a New Reverse Lookup Zone

Add-DnsServerPrimaryZone -NetworkId "192.168.1.0/24" -ZoneFile "1.168.192.in-addr.arpa.dns" -ZoneType ReverseLookup

Use this to set up reverse name resolution for the 192.168.1.0 network.

4. Add a New A Record

Add-DnsServerResourceRecordA -Name "web" -ZoneName "example.com" -IPv4Address "192.168.1.100"

Creates an A record pointing “web.example.com” to the IP address 192.168.1.100.

5. Add a CNAME Record

Add-DnsServerResourceRecordCName -Name "alias" -HostNameAlias "web.example.com" -ZoneName "example.com"

Creates a canonical name record pointing “alias.example.com” to “web.example.com”.

6. Add an MX Record

Add-DnsServerResourceRecordMX -Name "@" -MailExchange "mail.example.com" -Preference 10 -ZoneName "example.com"

Adds a Mail Exchange record to route emails through “mail.example.com”.

7. Remove a DNS Record

Remove-DnsServerResourceRecord -ZoneName "example.com" -RRType "A" -Name "web" -Force

Deletes an A record named “web” from the “example.com” zone.

8. View All DNS Records in a Zone

Get-DnsServerResourceRecord -ZoneName "example.com"

Lists all records within the specified DNS zone.

9. Clear DNS Cache on Client

Clear-DnsClientCache

Flushes the DNS resolver cache on the local client.

10. Flush DNS Server Cache

Clear-DnsServerCache

Clears all cached DNS entries on the DNS server.

11. Set DNS Server Addresses on a NIC

Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses ("8.8.8.8", "1.1.1.1")

Changes DNS servers on the “Ethernet” network adapter.

12. Get Current DNS Settings

Get-DnsClientServerAddress

Displays current DNS server settings for all adapters.

13. Export DNS Zone to File

Export-DnsServerZone -Name "example.com" -FileName "C:\Backup\example.com.dns"

Backs up the “example.com” zone to a file.

14. Import DNS Zone from File

Import-DnsServerZone -Name "example.com" -FileName "C:\Backup\example.com.dns"

Restores a zone from a previously backed-up file.

15. Monitor DNS Server Stats

Get-DnsServerStatistics

Displays various DNS server performance and operational statistics.

Conclusion

With PowerShell, DNS administration becomes faster, more reliable, and scriptable. Whether you’re adding records, configuring zones, or troubleshooting DNS issues, these commands will give you a solid foundation for managing your environment efficiently. Bookmark this list and incorporate it into your regular DNS maintenance routines.

By amit_g

Welcome to my IT Infra Blog! My name is Amit Kumar, and I am an IT infrastructure expert with over 11 years of experience in the field. Throughout my career, I have worked with a wide variety of systems and technologies, from network infrastructure and cloud computing to hardware and software development. On this blog, I aim to share my knowledge, insights, and opinions on all things related to IT infrastructure. From industry trends and best practices to tips and tricks for managing complex systems, my goal is to provide valuable information that will help IT professionals and enthusiasts alike. Whether you are a seasoned IT veteran or just getting started in the field, I hope you will find my blog to be a valuable resource. In addition to sharing my own thoughts and ideas, I also welcome feedback, comments, and questions from my readers. I believe that a collaborative approach is the best way to advance the field of IT infrastructure and I look forward to hearing from you. Thank you for visiting my blog, and I hope you will continue to follow along as I explore the fascinating world of IT infrastructure. Sincerely, Amit Kumar

Leave a Reply

Your email address will not be published. Required fields are marked *