4

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

ArgisIsland
  • 153
  • 1
  • 6

3 Answers3

5

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
ErikE
  • 4,746
  • 1
  • 20
  • 27
2

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.

TheCleaner
  • 32,627
  • 26
  • 132
  • 191
  • Thanks for this information. To be honest I didn't add the command directly as I use it in my script, just an example, so my call actually takes this into consideration. Your answer will be useful for others though I think, so I'm giving it an up vote. edit: or I would if I had enough reputation... – ArgisIsland Nov 22 '13 at 14:18
  • The requirement part was more interesting for me, thanks. However since it wasn't explicitly excluded from the requirements, I wasn't sure if earlier Windows versions are supported. This is unfortunate though, I guess I have to search for an alternative then. – ArgisIsland Nov 22 '13 at 14:21
  • 2
    @vm370 - see my final edit at the bottom...it only works on 8.1 or 2012 R2. You can google "add dns record powershell 2008" for some wmi cmdlets to do what you are after. If the answer is sufficient please mark it so that the question gets completed. – TheCleaner Nov 22 '13 at 14:21
0

Taken from here: http://daniel.streefkerkonline.com/2014/12/09/change-a-nics-dns-server-settings-with-powershell-and-wmi-setdnsserversearchorder/

Check this out:

The servers that we want to use

$newDNSServers = "192.168.1.1","192.168.1.2"

Get all network adapters that already have DNS servers set

$adapters = Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object {$_.DNSServerSearchOrder -ne $null}

Set the DNS server search order for all of the previously-found adapters

$adapters | ForEach-Object {$_.SetDNSServerSearchOrder($newDNSServers)}

billsecond
  • 199
  • 9