Skip navigation
DNS Creation in PowerShell

DNS Creation in PowerShell

Q. How can I create a DNS record in PowerShell?

A. To create DNS host records prior to Windows Server 2012 R2, Windows 8.1 and PowerShell v4 it was necessary to use the CreateInstanceFromTextRepresentation of the MicrosoftDNS_ResourceRecord WMI class which is documented at https://msdn.microsoft.com/en-us/library/windows/desktop/ms682714(v=vs.85).aspx and an example usage is shown below:

$dnsServer = "savdaldc01.savilltech.net"
$dnsZone = "savilltech.net"
$hostA = "test.savilltech.net"
# Set the class: 1 = Internet, 2 = CSNet, 3 = CHAOS, 4 = Hesiod
$recordClass = 1
$ttl = 3600
$IPAddress = "10.7.173.25"
#A type record
$dnsAType = [wmiclass]"root\MicrosoftDNS:MicrosoftDNS_AType"
# Use CreateInstanceFromPropertyData to create the host A record
$dnsAType.CreateInstanceFromPropertyData($dnsServer, $dnsZone, $hostA, $recordClass, $ttl, $IPAddress)

With PowerShell v4 and above it is much simpler. The Add-DnsServerResourceRecordA cmdlet can be used (there are other cmdlets for other types of record as documented at https://technet.microsoft.com/en-us/library/jj590772.aspx). The same result as the script above can be achieved using only the following:

Add-DnsServerResourceRecordA -IPv4Address 10.7.173.25 -Name test -ZoneName savilltech.net -TimeToLive 3600

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish