PowerShell DNS Records (Creating)

 PowerShell DNS KB ID 0001906

Problem

You can use PowerShell to create DNS records in a Windows environment, this is typically on a Windows Server OS, that is running DNS services. Below are some  methods (depending on whether you’re managing an Active Directory-integrated DNS zone or a standalone DNS server) to do this.

Solution

PowerShell DNS: Creating an A Record (Host Record)

To add an A record (IPv4 address) to a DNS zone, use the following syntax.

[box]

Add-DnsServerResourceRecordA -Name "my-server" -ZoneName "pnl.com" -IPv4Address "192.168.100.101"

[/box]

PowerShell DNS: Creating an AAAA Record (IPv6 Host Record)

To add an A record (IPv4 address) to a DNS zone, use the following syntax.

[box]

Add-DnsServerResourceRecordAAAA -Name "my-server" -ZoneName "pnl.com" -IPv6Address "2001:db8::2"

[/box]

PowerShell DNS: Creating an CNAME Record (Cananonical Name Record)

To add an CNAME record (IPv4 address) to a DNS zone, use the following syntax.

[box]

Add-DnsServerResourceRecordCName -Name "www" -ZoneName "pnl.com" -HostNameAlias "my-server.pnl.com"

[/box]

PowerShell DNS: Creating an MX Record (Mail Exchange)

To add an MX record for mail delivery to a DNS zone, use the following syntax, Note: This will create an MX record with a priority of 10.

[box]

Add-DnsServerResourceRecordMX -ZoneName "pnl.com" -Name "@" -MailExchange "mail-01.pnl.com" -Preference 10

[/box]

PowerShell DNS: Creating an PTR Record (Reverse DNS)

To add an PTR record (or a reverse DNS lookup record) the following syntax, Note: Assumes you already have a reverse lookup zones created.

[box]

Add-DnsServerResourceRecordPTR -Name "101" -ZoneName "100.168.192.in-addr.arpa" -PtrDomainName "my-server.pnl.com"

[/box]

Note: This creates a PTR Record for 192.168.100.101 that points back to my-server.pnl.com.

PowerShell DNS: Creating an TXT Record (For SPF, DKIM, etc)

To add an TXT record use the following syntax.

[box]

Add-DnsServerResourceRecord -DescriptiveText "v=spf1 mx -all" -Name text -Txt -ZoneName pnl.com 

[/box]

Using PowerShell for DNS record creation helps streamline the administrative workload, improves consistency, and reduces the potential for errors, especially in larger environments. It’s an efficient, flexible, and scalable solution that can significantly enhance the management and automation of DNS infrastructure. Whether for one-off record creation or bulk updates, PowerShell is a powerful tool for IT administrators.

Related Articles, References, Credits, or External Links

Setting up the Correct DNS Records for your Web or Mail Server

Add-DnsServerResourceRecord

BT Domains Center – Setup Your Mail Server DNS Records

KB ID 0000900 

Problem

If you are used to setting up DNS records, then the BT Web Portal (btdomainmanager.com) can be a little confusing. I was stuck yesterday, luckily I had another client I could get to check their records for me.

Solution

In the example below I’ve got two IP addresses to which I want mail delivering to, 123.123.123.123 and 123.123.123.125, (yours may be on completely different ranges, that’s OK.)

In addition to the two MX records, I’ve also setup two A (host) records that point the host-names mail and mail2 to those two IP addresses.

Note: Most of you, will only have one IP address, and one host record to create.

Related Articles, References, Credits, or External Links

Setting up the Correct DNS Records for your Web or Mail Server