Adding a DNS A record to a Win 2008R2 server from an Win 2008R2 server or Win7 via Powershell

I recently discovered that it is possible to simply automate DNS entry administration with a nice cmdlet:

Import-Module DnsServer
Add-DnsServerResourceRecordA -Name mail2 -IPv4Address 192.168.0.10 -ZoneName powershell.local

I'd like to run this one on a Windows 2008 R2 machine (it's called in a web service) to change a DNS entry on another one. I saw that Powershell v3 already supports this, but I couldn't get it to work on Powershell v4 either, apparently the module cannot be imported. Is this because I tested it on a Windows 7 machine? I have a Windows 7 development machine on which I'd like to develop and to debug it. Is it possible that I have to reload this module somehow? If yes, how can I do this?

I saw on the MS page that it is supported on Windows Server 2012, but I have no Win2012 system to test it on to confirm and switching the productive servers 2012 is currently not possible.

Thanks a lot in advance


You'll need to specify the DNS server, otherwise it runs on the local server, so if you are running this cmdlet remotely you'd need to specify where the DNS server is you want it to affect.

Use:

-ComputerName in the cmdlet and specify the name or IP of the DNS server you are wanting it to be changed on.

Specifies a DNS server. If you do not specify this parameter, the command runs on the local system. You can specify an IP address or any value that resolves to an IP address, such as a fully qualified domain name (FQDN), host name, or NETBIOS name.

However, the cmdlet only specifies Windows 8.1 and Windows 2012 R2. So it most likely won't run on anything prior to those OS'...that's why they specify it in the docs on Technet.


You need to install the remote server admin tools.

On a server they are installed as a feature.

For a client google "rsat windows 7" and download the installer.

After installation you get the powershell server admin modules available to the import-module cmd-let.

[EDIT] The DndServer module comes with the win8.1 RSAT. You can do it in other ways on win7 though, see the scripting guy: http://blogs.technet.com/b/heyscriptingguy/archive/2010/09/13/manage-dns-in-a-windows-environment-by-using-powershell.aspx

However I did a csv file import as I migrated a dns server just a couple of weeks ago (which I didn't think of as I wrote my answer). I found it easier to call dnscmd from powershell than to mess around.

Here is the actual execution I used, csv import and looping stripped away:

dnscmd $DNS_DNSServerName /recordadd $DNS_Domain $DNS_Name $DNS_ResourceType $DNS_Data