A DNS (Domain Name Server) is called the internet’s phone book that is responsible for translating the domain names into specific IP addresses so the computer can load the requested resources. The DNS server is in charge of managing DNS records. automatically. However, there comes a need to manage the tasks manually, such as creating, editing, adding, or removing DNS records. PowerShell can manage the DNS records with the aid of some specific DNS cmdlets.
This blog will overview the procedure to manage the DNS cmdlets.
Automate Boring Tasks with PowerShell DNS Cmdlets
These are the topics that will be approached in this guide:
- View DNS records with PowerShell DNS cmdlets.
- Add or remove A host records.
- Add or remove AAAA host records.
- Create a DNS zone.
- Create an alias record.
Approach 1: How to View DNS Records With PowerShell DNS Cmdlets?
The DNS records can be retrieved using the “Get-DnsServerResourceRecord” cmdlet. This cmdlet retrieves the resource entries from a particular DNS zone by specifying the “-ZoneName” parameter. For instance, overview the given code to get the resource records:
In the stated code above:
- First, the “Get-DnsServerResourceRecord” cmdlet is added.
- After that, the “-ZoneName” parameter is specified.
- Lastly, the server is specified in the zone name.
Approach 2: How to Add and Remove A Host Record?
The A host record uses the “IPv4” protocol and it can be added to the host record by executing the given code:
In the stated code snippet:
- First, write the “Add-DnsServerResourceRecordA” cmdlet.
- Then, add the “-Name” parameter and specify the hostname.
- After that, write the “-ZoneName” parameter and assign the zone address.
- Lastly, add the parameters “-AllowUpdateAny”, “-IPv4Address”, and “-TimeToLive”, and assign the stated values.
To remove the A host record, simply execute the given code:
According to the above code:
- First, specify the “Remove-DnsServerResourceRecord” cmdlet, followed by the “-ZoneName” parameter having the value “com” assigned to it.
- Then add another parameter “-RRType” parameter and specify the value “A”.
- Lastly, create a parameter “-Name” and assign the value “host12” to it, which is a host.
Approach 3: How to Add and Remove AAAA Host Records?
The only difference between A and AAAA is that A uses the “IPv4” protocol while the AAAA uses the “IPv6” protocol. The AAAA records can be added by executing the code below:
In the stated code above:
- First, specify the “Add-DnsServerResourceRecordAAAA” cmdlet.
- Then, write the “-Name”, “-ZoneName”, “-AllowUpdateAny”, “-IPv6Address”, and “-TimeToLive” parameters and assign the stated values.
In order to remove the AAAA host record, simply specify the value “AAAA” to the “-RRType” parameter:
Approach 4: How to Create a DNS Zone?
The DNS zone can be created by using the “Add-DnsServerPrimaryZone” cmdlet. This cmdlet adds a primary zone to a DNS server. For that reason, execute the below code:
According to the above code:
- First, add the “Add-DnsServerPrimaryZone” cmdlet, along with the “-Name” parameter having the value “com” assigned to it.
- Then, write the “-ReplicationScope” parameter and specify the value “Jungle” to it.
- Lastly, define the “-PassThru” parameter.
Approach 5: How to Create an Alias Record(CNAME)?
An alias record can be created using the “Add-DnsServerResourceRecordCName” cmdlet. It adds a type of CNAME resource record to the DNS server. To do so, execute the given code:
In the above-stated code:
- First, specify the “Add-DnsServerResourceRecordCName” cmdlet, along with the “-Name” parameter having the “serv1” value assigned to it.
- Then, specify the “-HostNameAlias” parameter and assign the value “google.com”.
- Lastly, specify the “-ZoneName” parameter and assign the value “com” to it.
You have learned about automating boring tasks with the PowerShell DNS cmdlet.
Conclusion
The DNS cmdlets in PowerShell are used to manage the DNS records. It creates, deletes, edits, or adds the DNS records. This write-up has covered all the aspects related to the automation of DNS-related tasks using the PowerShell DNS cmdlets.