PowershellGuru
  • Home
  • Active Directory Scripts
  • Script Repository
  • DHCP Scripts
  • DNS Scripts
  • Blogs
  • Community
  • Login
No Result
View All Result
PowershellGuru
  • Home
  • Active Directory Scripts
  • Script Repository
  • DHCP Scripts
  • DNS Scripts
  • Blogs
  • Community
  • Login
No Result
View All Result
PowershellGuru
No Result
View All Result
Home Powershell Script blogs

How to use PowerShell to manage DNS records (2022)

themeanmachine19@gmail.com by [email protected]
April 2, 2022
in Powershell Script blogs
0
How to use PowerShell to manage DNS records
Share on FacebookShare on Twitter

You might also like

Instant guide to convert ps2 to exe

Instant Guide To Convert PS1 To EXE (2022)

May 21, 2022
PowerShell tips and tricks

5 Useful PowerShell Tips and Tricks

May 15, 2022

Managing Domain Name System (DNS) records is a repetitive task that often necessitates manual intervention. It can be tedious for an administrator to maintain records for a domain, and it’s easy to lose track of which records need updating and which ones don’t.

In this article, we will go over how PowerShell can be used to facilitate the process of managing DNS records at scale by automating repetitive tasks and making it easier for administrators to keep track of their DNS record changes.With the use of PowerShell, we can create scripts that will automate some of these manual tasks saving time as well as effort.

 This article will teach you 3 easy steps that allow you to manage DNS records using PowerShell.

1. Add a DNS record

2. Modify an existing DNS record

3. Delete an existing DNS record

How to use PowerShell to manage DNS records

Add a DNS record using PowerShell

The Add-DnsServerResourceRecordA cmdlet adds a host address (A) record to a DNS zone. An IPv4 address is specified by an A record. Below is the sytax for Add-DnsServerResourceRecordA.

				
					Add-DnsServerResourceRecordA
   [-AllowUpdateAny]
   [-CreatePtr]
   [-Name] <String>
   [-IPv4Address] <IPAddress[]>
   [-ComputerName <String>]
   [-TimeToLive <TimeSpan>]
   [-ZoneName] <String>
   [-AgeRecord]
   [-PassThru]
   [-ZoneScope <String>]
   [-VirtualizationInstance <String>]
   [-CimSession <CimSession[]>]
   [-ThrottleLimit <Int32>]
   [-AsJob]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
				
			

#Add a A record to the Zone PowerShellguru.com

Below example shows how to add a record “testrecord” to the zone “powershellguru.com” with IPv4 address “175.18.99.23” and time to live set for 8 days.

				
					Add-DnsServerResourceRecordA -Name "Testrecord" -ZoneName "powershellguru.com" -AllowUpdateAny -IPv4Address "175.18.99.23" -TimeToLive 08:00:00
				
			

Modify existing DNS record using PowerShell

Set-DnsServerResourceRecord modifies a resource record object in a Domain Name System (DNS) zone. You can use the OldInputObject parameter to specify an existing resource record object to change, and the NewInputObject parameter to specify a new resource record. This cmdlet does not have the ability to change the Name or Type of a DNS server resource record object. Below is the syntax of Set-DnsServerResourceRecord

				
					Set-DnsServerResourceRecord
   [-NewInputObject] <CimInstance>
   [-OldInputObject] <CimInstance>
   [-ComputerName <String>]
   [-ZoneName] <String>
   [-PassThru]
   [-ZoneScope <String>]
   [-VirtualizationInstance <String>]
   [-CimSession <CimSession[]>]
   [-ThrottleLimit <Int32>]
   [-AsJob]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
				
			

Read the Basics of PowerShell from here

#Change the time span of a resource record

The time to live (TTL) value of the resource record named Host01 in the zone named contoso.com is changed to 2 hours in this example.The first command assigns to the variable $OldObj a resource record named Host01 in the zone contoso.com.The second command uses the.Clone() method to copy the variable $OldObj to a new variable $NewObj.The third command sets the $NewObj TTL time span to 2 hours.The fourth command sets the properties of $OldObj to the values specified in the previous command for $NewObj.

				
					$OldObj = Get-DnsServerResourceRecord -Name "Host01" -ZoneName "contoso.com" -RRType "A"
$NewObj = $OldObj.Clone()
$NewObj.TimeToLive = [System.TimeSpan]::FromHours(2)
Set-DnsServerResourceRecord -NewInputObject $NewObj -OldInputObject $OldObj -ZoneName "contoso.com" -PassThru

HostName                  RecordType Timestamp            TimeToLive      RecordData
--------                  ---------- ---------            ----------      ----------
Host01                       A          0                    02:00:00        2.2.2.2
				
			

 How to modify IPv4 address of an existing record

Delete existing DNS record using PowerShell

The Remove-DnsServerResourceRecord cmdlet deletes resource record objects from a DNS zone.

You can either specify an object or the RRtype, Name, and RecordData of the resource record you want to remove with the Get-DnsServerResourceRecord cmdlet. If an RRtype or name is specified and there are multiple resource records, you can specify the RecordData to delete a specific record. If you do not specify RecordData, the cmdlet deletes all records for the specified zone that match RRtype and Name. Below is the syntax for the same.

				
					Remove-DnsServerResourceRecord
      [-ZoneName] <String>
      [-PassThru]
      [-ComputerName <String>]
      [-Force]
      [-ZoneScope <String>]
      [-VirtualizationInstance <String>]
      [-RRType] <String>
      [-RecordData <String[]>]
      [-Name] <String>
      [-CimSession <CimSession[]>]
      [-ThrottleLimit <Int32>]
      [-AsJob]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]
				
			

#Remove an A record

The below example will remove the A type record with IP address “10.17.1.41” and record name as “Host01”.

				
					Remove-DnsServerResourceRecord -ZoneName "contoso.com" -RRType "A" -Name "Host01" -RecordData "10.17.1.41"
				
			

For more examples click here

Conclusion

Hope you have enjoyed reading How to use PowerShell to manage DNS records .PowerShell is a powerful, flexible tool that has a lot of uses and you might be surprised how much you can do using it, and managing DNS records is just one of them. There are many ways that you can use the PowerShell to manage your DNS records. I hope you have grasped some idea on managing DNS with PowerShell. 

If you have loved this article do check out the below as well.

https://powershellguru.com/dns-powershell-scripts/

 

close

DON’T MISS A POST

Keep up to date with PowershellGuru

Powershell Blogs

PowershellGuru provides the best PowerShell scripts available that can be used and download freely. Do Check our blogs to get updated regularly.

Check your inbox or spam folder to confirm your subscription.

themeanmachine19@gmail.com

[email protected]

Related Stories

Instant guide to convert ps2 to exe

Instant Guide To Convert PS1 To EXE (2022)

by [email protected]
May 21, 2022
0

Instant guide to convert ps1 to exe. How to convert ps1 to exe. PS2exe. Convert ps1 to exe using ps2exe.

PowerShell tips and tricks

5 Useful PowerShell Tips and Tricks

by [email protected]
May 15, 2022
0

Useful Powershell tips and tricks. PowerShell tips and tricks. Know Powershell tips and tricks. get-help. get-alias.

tips to manage hyper-v using powershell

5 Tips To Manage Hyper-V Using PowerShell

by [email protected]
May 1, 2022
0

Tips to manage hyper-v using PowerShell. How to manage Hyper-V using PowerShell. Powershell to manage Hyper-V. Hyper-v and PowerShell.

Mistakes To Avoid While Writing A Powershell Script

5 Big Mistakes To Avoid While Writing A Powershell Script

by [email protected]
April 30, 2022
0

Mistakes to avoid while writing a powershell script. PowerShell mistakes. Avoid these mistakes in a powershell script. PowershellGuru.

Next Post
Mistakes To Avoid While Writing A Powershell Script

5 Big Mistakes To Avoid While Writing A Powershell Script

Please login to join discussion

Recommended

Best Powershell tutorial for beginners

Best PowerShell Tutorial for Beginners (2021)

March 19, 2021
Pipeline in Powershell

3 Proven ways to Learn Pipeline in Powershell

July 4, 2021

About

Dhrub Bharali

PowerShell Enthusiast

Dhrub is hardcore Powershell enthusiast, he has wriiten more than 100 powershell scripts and he is the sole owner of PowerShellGuru.

Follow Us

Popular Story

  • Installing software remotely using powershell

    Easy way to install software remotely using PowerShell (2021)

    827 shares
    Share 331 Tweet 207
  • Detect Log4j vulnerable servers using PowerShell

    753 shares
    Share 301 Tweet 188
  • How to find NTP Server using PowerShell?

    738 shares
    Share 295 Tweet 185
  • Get-LocalGroupMember: Find Local admin using PowerShell (2021)

    728 shares
    Share 291 Tweet 182
  • Get installed software list quickly using PowerShell (2021)

    695 shares
    Share 278 Tweet 174
  • Home
  • Active Directory Scripts
  • Script Repository
  • DHCP Scripts
  • DNS Scripts
  • Blogs
  • Community
  • Login

© 2022 PowershellGuru- PowerShell Scripts For Automation

No Result
View All Result
  • Home
  • Active Directory Scripts
  • Script Repository
  • DHCP Scripts
  • DNS Scripts
  • Blogs
  • Community
  • Login

© 2022 PowershellGuru- PowerShell Scripts For Automation