Using PowerShell to Manage Windows Server DNS entries

Firstly, Happy new year. Anyway, I was recently tasked with creating a large number of DNS entries on our internal DNS servers. To accomplish this I decided to use PowerShell to perform an import of a CSV file that I had been given that already had my DNS entries. There was a header row with HostName and IPAddress as columns and then dozens of lines entries that needed to become DNS A Records on our server.

So the first command I used to Import these records was the below (replace adatum.com.au with your DNS zone) and DNSentries.csv with your filename.
Import-CSV C:\Scripts\DNSentries.csv | %{ Add-DNSServerResourceRecordA -ZoneName adatum.com.au -Name $_."HostName" -IPv4Address $_."IPAddress" }

After completing that I noticied that some had a typo (the file was given to me) so instead of going in and manually removing the ones that were wrong, I again used PowerShell to remove them with the following command:
Import-CSV C:\Scripts\DNSentries.csv | %{ Remove-DnsServerResourceRecord -ZoneName "adatum.com.au" -RRType "A" -Name $_."HostName" -RecordData $_."IPAddress" }

Using the above commands you can quickly and easily add or remove DNS entries from your Windows Server DNS Infrastructure using entries from a CSV file.

Leave a Reply