---
title: "Automate DNS Tasks with PowerShell DNS Cmdlets"
description: "Streamline your DNS management using PowerShell DNS cmdlets and say goodbye to tedious tasks."
canonical: "https://adamtheautomator.com/powershell-dns/"
---

# Automate DNS Tasks with PowerShell DNS Cmdlets

> Streamline your DNS management using PowerShell DNS cmdlets and say goodbye to tedious tasks.

Source: https://adamtheautomator.com/powershell-dns/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Automate DNS Tasks with PowerShell DNS Cmdlets](https://adamtheautomator.com/wp-content/uploads/2019/07/photo-1542221947260-bfa41adbce43.jpg)

# Automate DNS Tasks with PowerShell DNS Cmdlets

[![](https://secure.gravatar.com/avatar/c7a74bc8c8cff3fbf86e12939764aae0a53a7207d518c3be47a8763a25c74245?s=192&d=mm&r=g)David Lamb](https://adamtheautomator.com/author/david/)25 July 20194 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Microsoft DNS](/tag/microsoft-dns/)[PowerShell](/tag/powershell/)

Table of Contents

*   [Viewing DNS Records with PowerShell DNS Cmdlets](#viewing-dns-records)
*   [Adding and Removing A Host Records](#adding-and-removing-a-host-records)
*   [Adding and Removing AAAA Host Records](#adding-and-removing-aaaa-host-records)
*   [Adding Reverse Lookup Records (PTR)](#adding-reverse-lookup-records-ptr-)
*   [Creating a DNS Zone](#creating-a-dns-zone)
*   [Adding Alias Records (CNAME)](#adding-alias-records-cname-)
*   [Summary](#summary)

DNS records are typically managed dynamically by your DNS server. However, at times, you may find that you need to manually create, edit, or remove various types of DNS records. Or to even add various DNS tasks to automation scripts. It is at times like this that using PowerShell DNS cmdlets is the way to go.

Not a reader? Watch this related video tutorial!

**_Not seeing the video? Make sure your ad blocker is disabled._**

> _This blog post has a companion video created by [TechSnips contributor, David Lamb](https://techsnips.io/contributors/david-lamb/). Feel free to have a watch or, if you prefer text, read on!_

## Viewing DNS Records with PowerShell DNS Cmdlets

You can view all of the resource records for a given [DNS zone](https://adamtheautomator.com/powershell-add-dns-zone/ "DNS zone") by simply using the PowerShell DNS cmdlet `Get-DnsServerResourceRecord`. Using this cmdlet, you can specify the `ZoneName` parameter which will list all DNS records in that zone.

As you can see below, this generates quite a lengthy list of records.

```powershell
PS51> Get-DnsServerResourceRecord -ZoneName corp.ad
```

![Listing DNS records with PowerShell](/wp-content/uploads/2019/07/TS-Demo-DNS-Records-01.png)

Listing DNS records with PowerShell

This behavior highlights one of the advantages of this particular cmdlet over the graphical DNS console. The view gives you all of the records for this zone, regardless of which folder they are in. In the graphical console, it would take quite some time to piece this information together.

Now thin out this list a bit. Using the same cmdlet, but adding the `RRType` parameter to search for A records (IPv4 hosts) and filtering for records where the _Time To Live (TTL)_ is greater than 15 minutes gives us a bit more of a manageable list. You can use the [`Where-Object`](https://adamtheautomator.com/powershell-where-object/ "Where-Object") cmdlet to filter on many different DNS record properties.

Related:[How to Use PowerShell Where-Object to Filter All the Things](https://adamtheautomator.com/powershell-where-object/)

```powershell
PS51> Get-DnsServerResourceRecord -ZoneName corp.ad -RRType A | Where-Object TimeToLive -GE "00:15:00"
```

![Finding DNS records with a TimeToLive greater than 15 minutes](/wp-content/uploads/2019/07/TS-Demo-DNS-Records-02.png)

Finding DNS records with a TimeToLive greater than 15 minutes

Taking this one step further, you can also search for records in a different DNS zone and even on different DNS servers.

In the example below, we will search for A records in the _canada.corp.ad_ zone on DNS server _DC03_

```powershell
PS51> Get-DnsServerResourceRecord -ComputerName DC03 -ZoneName canada.corp.ad -RRType A
```

![Finding DNS A records](/wp-content/uploads/2019/07/TS-Demo-DNS-Records-03.png)

Finding DNS A records

## Adding and Removing A Host Records

To add a host record, you will need to use the PowerShell DNS cmdlet `Add-DnsServerResourceRecordA`. In the example below, you need to add a host record for a new printer that you are adding to the network. It will be added to the corp.ad zone with the name reddeerprint01, and its IP address is 192.168.2.56.

```powershell
PS51> Add-DnsServerResourceRecordA -Name reddeerprint01 -ZoneName corp.ad -IPv4Address 192.168.2.56
PS51> Get-DnsServerResourceRecord -ZoneName corp.ad -RRType A
```

![Creating a DNS record](/wp-content/uploads/2019/07/TS-Demo-DNS-Records-04.png)

Creating a DNS record

If it turns out that you need to remove a record, perhaps the printer has been decommissioned, you can use the following code to remove the host record that we just created:

```powershell
PS51> Remove-DnsServerResourceRecord -ZoneName corp.ad -Name reddeerprint01 -RRType A
```

## Adding and Removing AAAA Host Records

It is also just as easy to add an IPv6 host record. Of course, these records differ slightly, as they are listed as AAAA records. You may notice that we are now using the PowerShell DNS cmdlet `Add-DnsServerResourceRecordAAAA`. It’s a subtle change, but an important one.

Add a record to the _corp.ad_ zone for the new IT Intranet server at fc00:0128 and then quickly verify that it has been created with the following command.

```powershell
PS51> Add-DnsServerResourceRecordAAAA -Name it-intranet -ZoneName corp.ad -IPv6Address "fc00::0128"
PS51> Get-DnsServerResourceRecord -ZoneName corp.ad -RRType AAAA
```

![Creating an AAA host record](/wp-content/uploads/2019/07/TS-Demo-DNS-Records-05.png)

Creating an AAA host record

## Adding Reverse Lookup Records (PTR)

Using PowerShell DNS cmdlets, you can also add PTR records. A reverse lookup record allows the client to query a DNS server to request the hostname for a supplied IP address.

Creating a PTR record is a relatively easy process, but there is one important bit of information you will need to know before you start adding PTR records. Reverse lookup zones are not created by default. You will need to set up your reverse lookup zone prior to adding records. Fortunately, it is relatively easy to do.

## Creating a DNS Zone

Use the PowerShell DNS cmdlet `Add-DnsServerPrimaryZone` to create a new DNS zone. In this instance, since you’re creating a reverse lookup zone, provide it with the Network ID.

In this example, I have also chosen to set the replication scope to the entire AD forest, and I have specifically targeted _DC03_ as the preferred DNS server:

```powershell
PS51> Add-DnsServerPrimaryZone -ComputerName DC03 -NetworkId "192.168.2.0/24" -ReplicationScope Forest
PS51> Get-DnsServerZone -ComputerName DC03
```

![Creating a DNS primary zone](/wp-content/uploads/2019/07/TS-Demo-DNS-Records-06.png)

Creating a DNS primary zone

Now that the reverse lookup zone is in place, you can add a PTR record for a new printer called _CYQF-Printer-01.canada.corp.ad_ that has an IP address of 192.168.2.56. As this record is for the _canada.corp.ad_ zone, you will be targeting the DNS server _DC03_.

Now that the zone is created, let’s create a PTR record using the `Add-DnsServerResourceRecordPtr` command. When using this cmdlet, it is important to note a couple of things.

*   You need to specify the zone name using the network ID in reverse order, then add _.in-addr.arpa_. So for our _192.168.2.0/24_ network ID, the zone name is _2.168.192.in-addr.arpa_.
*   The `Name` parameter is the host portion of the IP address. For our printer at 192.168.2.56, the `Name` is _56_.

Once you have those pieces of information, the code required to create the PTR record is relatively simple, if a bit long:

```powershell
PS51> Add-DnsServerResourceRecordPtr `
    -Name "56" `
    -PtrDomainName "CYQF-Printer-01.canada.corp.ad" `
    -ZoneName "2.168.192.in-addr.arpa" `
    -computerName DC03

PS51> Get-DnsServerResourceRecord -ComputerName DC03 -ZoneName "2.168.192.in-addr.arpa"
```

Related: [PowerShell Splatting: What is it and How Does it Work?](https://adamtheautomator.com/powershell-splatting/)

![Creating a PTR record](/wp-content/uploads/2019/07/TS-Demo-DNS-Records-07.png)

Creating a PTR record

## Adding Alias Records (CNAME)

To finish off this tutorial, create a host alias record or CNAME record using the `Add-DnsServerResourceRecordCName` cmdlet.

These records allow you to specify an alias for an existing host record in the zone. This becomes especially useful, for example, if you want to provide your finance users with an address for their web-enabled finance app.

You could create an alias called _finance_, and point it to the webserver webapp25.corp.ad. Once the app is migrated to the new webserver with a new hostname, you’d then change the CNAME record to point _finance_ that points to the new host. This way, the users don’t have to update their bookmarks. They can continue to access their application using the address _finance.corp.ad_.

```powershell
PS51> Add-DnsServerResourceRecordCName -ZoneName corp.ad -HostNameAlias "webapp25.corp.ad" -Name "finance"
PS51> Get-DnsServerResourceRecord -ZoneName corp.ad -RRType CName
```

![Creating a CNAME record](/wp-content/uploads/2019/07/TS-Demo-DNS-Records-08.png)

Creating a CNAME record

If you’d like to dive deeper into DNS and see some more advanced capabilities, be sure to check out all of the [other DNS posts here](https://adamtheautomator.com/tag/microsoft-dns/).

## Summary

This concludes our tutorial on using PowerShell with DNS records. With the knowledge you’ve accumulated here, you should now be able to manage interactively or even automate large swaths of DNS records if you set your mind to it!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-dns%2F&text=Automate%20DNS%20Tasks%20with%20PowerShell%20DNS%20Cmdlets)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-dns%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-dns%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2020/03/resolve-dns-name.jpg)

### [Resolve-DnsName: Master DNS Record Lookup in PowerShell](/resolve-dnsname/)

Master the Resolve-DnsName cmdlet for DNS record lookup in PowerShell. Learn the differences from other tools and enhance your IT skills.

![](https://adamtheautomator.com/wp-content/uploads/2019/07/dns-1-.jpg)

### [PowerShell DNS Zone Management Made Easy](/powershell-add-dns-zone/)

Save time and effort by using PowerShell to add and manage DNS zones in this step-by-step tutorial.

![](https://adamtheautomator.com/wp-content/uploads/2019/07/tracking-iterative-public-dns-queries-dns.png)

### [WireShark DNS Filtering: A PowerShell Setup Guide](/wireshark-dns-filter/)

Setup WireShark DNS filters like a pro. Step-by-step guide on tracking down Iterative DNS queries.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
