Keith Smith - My Blog - Twitter @_KeithIT

Powershell add A resource records to DNS

Tuesday, September 18, 2018 - by Keith A. Smith

I wanted to take sometime to write up a quick how to for adding A resource records into a windows DNS server via powershell. In my case this is something that must take place before you use a product like observium because it requires all the network devices to have A resource record in DNS. To create these records it's best to do it in via scripting, in this case powershell using the below 3 cmdlets:

Add-DnsServerResourceRecordA

Add-DnsServerResourceRecord

Get-DnsServerResourceRecord

 

For a single entry you can use the following in powershell

Add-DnsServerResourceRecordA -Name Device1 -IPv4Address 192.168.9.10 -ZoneName yourdnszonename.net-ComputerName ADServername

The command is broken down below:

Add-DnsserverResourceRecordA = This is the CMDLET used to add A resource record only

-Name = -Name of the A resource record

-IPv4Address = Is the ip address of the resource

-ZoneName = is the zonename you are adding your record to

-ComputerName = -ComputerName is the name for Dns Server

-CreatePtr = This is optional, if you want to create ptr (Reverse lookup record entry).

 

Note: To view the changes in DNS manager you will need to right click and refresh the zone, if you have already opened DNS manager.

For a multiple entry situation you would need to do the following in powershell

To add multiple resource record from csv file, Here is below step by step tutorial. I have saved excel file as csv. (and it is saved in c:\temp location)

Open up a spreadsheet program and name the first column Name (this is the name of the device) the next column should be named IPv4Address (here you would put the static ip of the device. You would need add all your devices in the aforementioned columns.

Once your csv file is completed fire up powershell and run the following (modified the below path as needed)
Import-Csv driveletter:\folder\DNSEntries.csv | ForEach-Object { Add-DnsServerResourceRecordA -Name $_.Name -IPv4Address $_.IPv4Address -ZoneName yourdnszonename.net -ComputerName ADServername}

 

Note: To view the changes in DNS manager you will need to right click and refresh the zone, if you have already opened DNS manager.


-End

  Share Post   

View Comments Comments


Leave a Comment