PowerShell is a task automation and configuration management framework developed by Microsoft that cmdlets can be used to automate tasks in Windows operating systems. This article will teach you how to use PowerShell for DNS records.
PowerShell is a command-line tool that allows users to perform various tasks on their computer. One of the many uses for PowerShell is changing DNS records. This article will show you how to use PowerShell for DNS Records. Read more in detail here: powershell change dns a record ip address.
Your DNS server usually manages DNS records dynamically. However, you may need to manually add, amend, or delete certain sorts of DNS entries from time to time. Alternatively, numerous DNS tasks may be added to automation scripts. It’s moments like this when PowerShell for DNS records comes in handy.
David Lamb, a TechSnips contributor, developed a video to accompany this blog entry. Feel free to look at your watch or continue reading if you prefer text.
Looking at DNS Records
Using the PowerShellGet-DnsServerResourceRecord cmdlet, you may see all of the resource records for a specified DNS zone. You may use the ZoneName option with this cmdlet to get a list of all DNS entries in that zone.
As you can see in the screenshot below, this results in a long list of records.
PS51> Get-DnsServerResourceRecord -ZoneName corp.ad
Using PowerShell to list DNS records
One of the benefits of this cmdlet over the graphical DNS interface is that it behaves like this. The view displays all records for this zone, regardless of the folder they are located in. It would take a long time to pull this information together in the graphical terminal.
Now it’s time to whittle down this list. Using the same cmdlet but filtering for records with a Time To Live (TTL) more than 15 minutes and using the RRType option to search for A records (IPv4 hosts) gives us a more manageable list. The Where-Object cmdlet may be used to filter on a variety of DNS record attributes.
PS51> Get-DnsServerResourceRecord -ZoneName corp.ad -RRType A | Where-Object TimeToLive -GE “00:15:00”
Finding DNS entries with a TimeToLive of more than 15 minutes is difficult.
You may even search for records in a different DNS zone or even on other DNS servers if you want to take it a step further.
In the example below, we’ll use DNS server DC03 to look for A records in the canada.corp.ad zone.
PS51> Get-DnsServerResourceRecord -ComputerName DC03 -ZoneName canada.corp.ad -RRType A
Searching for DNS A records
A Host Record’s Adding and Removing
You’ll need to use the Add-DnsServerResourceRecordA cmdlet to add a host record. You’ll need to create a host record for a new printer you’re adding to the network in this example. It will be assigned the name reddeerprint01 and the IP address 192.168.2.56 in the corp.ad zone.
PS51> Add-DnsServerResourceRecordA -Name reddeerprint01 -ZoneName corp.ad -IPv4Address 192.168.2.56 PS51> Get-DnsServerResourceRecord -ZoneName corp.ad -RRType A
Creating a Domain Name System (DNS) record
If it turns out that you need to delete a record, possibly because the printer has been deactivated, you can remove the host record that we just established using the following code:
PS51> Remove-DnsServerResourceRecord -ZoneName corp.ad -Name reddeerprint01 -RRType A
AAAA Host Records: Adding and Removing
Adding an IPv6 host record is just as simple. These records, however, vary somewhat since they are categorized as AAAA records. You’ll note that we’ve changed our cmdlet to Add-DnsServerResourceRecordAAAA. It’s a little adjustment, but it’s significant.
Add a record for the new IT Intranet server at fc00:0128 to the corp.ad zone, and then quickly check that it has been established using the command below.
PS51> Add-DnsServerResourceRecordAAAA -Name it-intranet -ZoneName corp.ad -IPv6Address “fc00::0128” PS51> Get-DnsServerResourceRecord -ZoneName corp.ad -RRType AAAA
Creating a AAA host record is a simple process.
Adding Records for Reverse Lookup (PTR)
PTR records may be added to DNS records using PowerShell. A reverse lookup record enables a client to ask a DNS server for the hostname associated with an IP address.
Although Creating a PTR record is a simple process. is a simple operation, there is one critical piece of information you should be aware of before you begin. By default, no reverse lookup zones are established. Prior to adding records, you must first set up your reverse lookup zone. It is, fortunately, quite simple to do.
Creating a Domain Name System (DNS) Zone
Create a new DNS zone using the Add-DnsServerPrimaryZone cmdlet. Because you’re constructing a reverse lookup zone in this case, give it the Network ID.
I’ve also opted to set the replication scope to the full AD forest in this example, and I’ve designated DC03 as the preferred DNS server:
PS51> Add-DnsServerPrimaryZone -ComputerName DC03 -NetworkId “192.168.2.0/24” -ReplicationScope Forest PS51> Get-DnsServerZone -ComputerName DC03
Creating a main zone in DNS
You may now add a PTR record for a new printer named CYQF-Printer-01.canada.corp.ad with an IP address of 192.168.2.56 to the reverse lookup zone. You’ll be addressing DNS server DC03 since this record is for the canada.corp.ad zone.
Let’s use the Add-DnsServerResourceRecordPtr command to generate a PTR record now that the zone has been formed. There are a few considerations to keep in mind while using this cmdlet.
- The zone name must be specified using the network ID in reverse order, followed by.in-addr.arpa. The zone name for our 192.168.2.0/24 network ID is 2.168.192.in-addr.arpa.
- The Name parameter is the IP address’s host component. The Name for our printer at 192.168.2.56 is 56.
Once you have those bits of information, the code to generate the PTR record is rather straightforward, although a little lengthy:
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”
Creating a PTR record is a simple process.
Alias Records are records that have been given a different name (CNAME)
To complete this lesson, use the Add-DnsServerResourceRecordCName cmdlet to establish a host alias or CNAME record.
You may use these records to create an alias for an existing host record in the zone. For example, if you want to give your financial consumers with a URL for their web-enabled finance software, this is extremely handy.
You may create a financial alias and point it to webapp25.corp.ad as a web server. After migrating the app to a new web server with a new hostname, you’ll need to update the CNAME record to point finance to the new host. Users will not have to change their bookmarks as a result of this. They may continue to use the address finance.corp.ad to access their application.
PS51> Add-DnsServerResourceRecordCName -ZoneName corp.ad -HostNameAlias “webapp25.corp.ad” -Name “finance” PS51> Get-DnsServerResourceRecord -ZoneName corp.ad -RRType CName
Adding a CNAME record to a domain
Check out all of the other DNS articles here if you want to learn more about DNS and see some more sophisticated features.
This finishes our PowerShell with DNS records lesson. If you put your mind to it, you should be able to handle vast swathes of DNS records interactively or even automate them using the information you’ve gained here.
PowerShell is a command-line tool that allows users to perform tasks with ease. In this tutorial, I will show you how to use PowerShell for DNS Records. Reference: get dns records powershell.
Frequently Asked Questions
How do I extract DNS records?
A: You can extract DNS records from a text file. To do this, open the files in Notepad and copy all of the text in that file into one new document by pressing Ctrl+v on your keyboard or using Edit > Paste Special > From Text Documents
How do I find my DNS resource records?
A: If you are unsure how to find your DNS resource records, please contact the provider of your current internet connection.
How do I get all DNS records for a domain?
A: You can use the nslookup command-line utility to find all DNS records for a given domain.
- add dns record powershell
- powershell get all dns records for ip
- export all dns zones and records with powershell