DNS Records Creation

Glenn Maxwell 10,781 Reputation points
2021-09-12T18:43:56.033+00:00

Hi All

i want to create host record and cname record using powershell commands.

HostRecord: server01.contoso.com pointing to ip 172.18.205.10 with pointer record created.
CNAMERecord: test1 pointing to server01.contoso.com

Please validate if the below syntaxes are correct.

Add-DnsServerResourceRecordA -Name server01 -ZoneName contoso.com -IPV4Address 172.18.205.10 -ComputerName dc01.contoso.com -CreatePtr -TimetoLive 00:03:00

Add-DnsServerResourceRecordCName -ZoneName contoso.com -HostNameAlias "server01.contoso.com" -Name "test1" -ComputerName dc01.contoso.com -CreatePtr -TimetoLive 00:03:00

i also want to modify the records please guide me with the sytaxes.
i.e server01.contoso.com pointing to ip 172.18.205.11
cname record: test2 pointing to server01.contoso.com

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,462 questions
0 comments No comments
{count} votes

Accepted answer
  1. Limitless Technology 39,511 Reputation points
    2021-09-13T12:50:42.97+00:00

    Hello GlennMaxwell,

    The commands are correct, you can check them here:
    https://learn.microsoft.com/en-us/powershell/module/dnsserver/add-dnsserverresourcerecorda?view=windowsserver2019-ps
    and
    https://learn.microsoft.com/en-us/powershell/module/dnsserver/add-dnsserverresourcerecordcname?view=windowsserver2019-ps

    First ensure that you have the RSAT installed on your Windows machine

    1. Run: DISM.exe /Online /Get-Capabilities
      2, install the RSAT by copying the Capability name and composing the command , example: DISM.exe /Online /add-capability /CapabilityName:Rsat.GroupPolicy.Management.Tools~~~~0.0.1.0
    2. Make sure that the DNS Module is correctly enabled by running the Powershell command: Get-Module DNSServer –ListAvailable

    For modifying A HOST record, is not as simple, as it requires some scripting experience, because you can't just overwrite, but instead clone the record, assign new value, then remove the old one. Luckily for CNAME, just running Add-DnsServerResourceRecordCName with the new value will successfully overwrite.

    For more info: https://learn.microsoft.com/en-us/powershell/module/dnsserver/set-dnsserverresourcerecord?view=windowsserver2019-ps

    Hope this helps,
    Best regards,

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Andreas Baumgarten 104K Reputation points MVP
    2021-09-12T18:55:21.47+00:00
    0 comments No comments

  2. Rich Matheisen 45,906 Reputation points
    2021-09-12T21:13:09.717+00:00

    Remove the -CreatePtr parameter from the Add-DnsServerResourceRecordCName. You created the PTR record when you added the "A" record so there's no need to do it again.

    0 comments No comments

  3. Glenn Maxwell 10,781 Reputation points
    2021-09-13T01:18:38.697+00:00

    Please validate the below syntaxes, is TTL 00:03:00 the default valute?

    New HostRecord: server01.contoso.com pointing to ip 172.18.205.10 with pointer record created.
    New CNAMERecord: test1 pointing to server01.contoso.com

    Add-DnsServerResourceRecordA -Name server01.contoso.com -ZoneName contoso.com -IPV4Address 172.18.205.10 -ComputerName dc01.contoso.com -CreatePtr -TimetoLive 00:03:00   
    
    Add-DnsServerResourceRecordCName -ZoneName contoso.com -HostNameAlias "server01.contoso.com" -Name "test1" -ComputerName dc01.contoso.com -TimetoLive 00:03:00
    

    Modifying Host Record from server01.contoso.com to server01.contoso.com(in the below syntax i am using createptr i.e if already a record exists and if it doesnot have pointer record)
    Modifying cname from test1 to test2(in the below syntax i am using createptr i.e if already a record exists and if it doesnot have pointer record)

    Set-DnsServerResourceRecord -NewInputObject server02.contoso.com -OldInputObject server01.contoso.com -ZoneName contoso.com -ComputerName dc01.contoso.com -CreatePtr -TimetoLive 00:03:00  
    
    Set-DnsServerResourceRecord -ZoneName contoso.com -HostNameAlias "server01.contoso.com" -Name "test2" -ComputerName dc01.contoso.com -CreatePtr -TimetoLive 00:03:00
    

    To validate the record is the syntax correct

    resolve-DNSName server02.contoso.com -Type All
    resolve-DNSName test2 -Type All