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

More Posts

Renaming a Hyper-V Failover Cluster

If you find yourself taking over a cluster with a name that is silly or doesn’t make sense, you can rename it without much issue. Your main thing to watch out for are backup software that target the cluster (such as Veeam or DPM). You just need to ensure they are reconfigured to use the […]

Solving the FIM (Forefront Identity Manager 2010 R2) FIMService start timeout (Portal) and getting it to Start

We were recently making changes to our FIM environment where our Forefront Identity Manager boxes required restarts.  With FIM we’re always making changes in our Development kit before moving into production (which is something everyone should try do).  We quickly found that we couldn’t get back into the FIM portal and taking a quick look […]

Allowing DirectAccess to other internal Subnets or VLANs in your Network

If you’ve got DirectAccess running in your environment for remote access you’ll know how great and seamless it is for your end users. For businesses with large segmented internal networks we need to make sure that your external users can access all of the internal resources they need. For this to happen we need to […]