Create & Manage DNS Zones and Records with PowerShell

A Windows administrator can use the nice previous Dnscmd cli device or DNSServer module for PowerShell to handle DNS zones and information. In this text we’ll cowl the fundamental operations of bulk creating, modification, and eradicating totally different DNS information or zones utilizing PowerShell.

DNSServer PowerShell Module

The DNSServer module for PowerShell is part of RSAT. , and on Windows Server you possibly can allow the module utilizing Server Manager GUI (Role Administration Tools -> DNS Server Tools).

install DNS Server Tools with DNSServer module for PowerShell

Make positive the DNSServer PowerShell module is set up in your pc:

Get-Module DNSServer –ListAvailable

You can show the record of instructions in it (the module model for Windows Server 2016 has 134 cmdlets):

Get-Module DNSServer

Get-Module DNSServer

Manage DNS Zones with PowerShell

Display the record of DNS zones in your server (in our case, it’s a area controller):

Get-DnsServerZone –PcName dc01

To add a brand new major DNS zone named, run this command:

Add-DnsServerMainZone -Name -ReplicationScope "Forest" –PassThru

As you possibly can see, the first DNS zone built-in into Active Directory has been created (isDsIntegrated=True).


You can create a Reverse Lookup Zone:

Add-DnsServerMainZone -NetworkId "" -ReplicationScope Domain

To synchronize a brand new zone with different DCs within the area, run the next command:

Sync-DnsServerZone –passthru

Display the record of information within the new DNS zone (it’s empty):

Get-DnsServerUseful resourceRecord -PcName dc01 -ZoneName contoso.native


To take away the DNS zone, use the command:

Remove-DnsServerZone -Name -PcName dc01

It may even take away all current DNS information within the zone.

Managing DNS Records with DNSServer PowerShell Module

To create a brand new A file for the host within the specified DNS zone, use this command:

Add-DnsServerUseful resourceRecordA -Name ber-rds1 -IPv4Address -ZoneName -TimeToStay 01:00:00

To add a PTR file to the Reverse Lookup Zone, you possibly can add –CreatePtr parameter to the earlier command or create the pointer manually utilizing the Add-DNSServerUseful resourceRecordPTR cmdlet:

Add-DNSServerUseful resourceRecordPTR -ZoneName -Name 33 -PTRDomainName

To add an alias (CNAME) for the precise A file, run this command:

Add-DnsServerUseful resourceRecordCName -ZoneName -Name Ber-RDSFarm -HostNameAlias

To change (replace) the IP tackle within the A file, you’ll have to apply fairly a posh technique since you can not change an IP tackle of a DNS file straight:

$NewADNS = get-DnsServerUseful resourceRecord -Name ber-rds1 -ZoneName -PcName dc01
$OldADNS = get-DnsServerUseful resourceRecord -Name ber-rds1 -ZoneName -PcName dc01

Then change the IPV4Address property of the $NewADNS object:

$NewADNS.RecordInformation.IPv4Address = [System.Net.IPAddress]::parse('')

Change the IP tackle of the A file utilizing the Set-DnsServerUseful resourceRecord cmdlet:

Set-DnsServerUseful resourceRecord -NewInputObject $NewADNS -PreviousInputObject $OldADNS -ZoneName -PcName dc01

Make positive that the IP tackle of the A file has modified:

Get-DnsServerUseful resourceRecord -Name ber-rds1 -ZoneName

Change/Update DNS Host Record IP Address via PowerShell

You can show the record of DNS information of the identical kind through the use of the –RRType parameter. Let’s show the record of CNAME information within the specified DNS zone:

Get-DnsServerUseful resourceRecord -PcName DC01 -ZoneName -RRType CNAME

Get-DnsServerResourceRecord RRType

You also can use filters by any DNS file parameters utilizing Where-Object. For instance, to show the record of A information containing rds phrase of their hostnames:

Get-DnsServerUseful resourceRecord -ZoneName -RRType A | Where-Object HostName -like "*rds*"

Get-DnsServerResourceRecord Where-Object HostName like

To take away DNS information, the Remove-DnsServerUseful resourceRecord cmdlet is used.

For instance, to take away a CNAME file, run the command:

Remove-DnsServerUseful resourceRecord -ZoneName woshub.native -RRType CName -Name Ber-RDSFarm

To take away an A DNS file:

Remove-DnsServerUseful resourceRecord -ZoneName woshub.native -RRType A -Name ber-rds1 –Force

To take away a PTR file from a Reverse Lookup Zone:

Remove-DnsServerUseful resourceRecord -ZoneName “” -RRType “PTR” -Name “33”

How to Create Multiple A and PTR DNS Records from a .CSV File?

Suppose, you wish to create a number of A information at a time within the particular DNS Forward Lookup Zone. You can add them one-by-one utilizing the Add-DnsServerUseful resourceRecordA cmdlet, however it’s simpler so as to add A information in bulk from a .CSV file.

Create a textual content file NewDnsRecords.txt with the names and IP addresses you wish to add to DNS. The txt file format is as follows:

HostName, IPAddress

Adding Multiple DNS Records From .TXT/ .CSV File with PowerShell Script

To create A information within the zone in response to the information in your TXT/CSV file, use the next PowerShell script:

Import-CSV "C:PSNewDnsRecords.txt" | %

If you wish to add information to the Reverse Lookup Zone on the identical time, add the –CreatePtr parameter to your Add-DNSServerUseful resourceRecordA command.

Then utilizing DNS Manager console (dnsmgmt.msc) or Get-DnsServerUseful resourceRecord -ZoneName woshub.native be sure that all DNS information have been created efficiently.

Bulk add DNS recordes using PoweShell

If you wish to add PTR information to the Reverse Lookup Zone in bulk, create a textual content or a CSV file with the next construction:


Then run the script:

Import-CSV "C:PSNewDnsPTRRecords.txt" | %

Make positive that your PTR information appeared within the DNS Reverse Lookup Zone.

Check Also

How to Clear RDP Connections History in Windows?

The built-in Windows Remote Desktop Connection (RDP) consumer (mstsc.exe) saves the distant pc title (or …

Leave a Reply

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