Remotely set DNS Primary and Secondary Servers via PowerShell

Create a text file with a list of server names that you would like to change Primary & Secondary DNS for:

remotednschange1

 

#PowerShell Script:
$computer = get-content C:\temp\servers.txt
$DNSServers = “192.168.1.19”,”192.168.1.30″
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq “TRUE”}
Foreach($NIC in $NICs) {$NIC.SetDNSServerSearchOrder($DNSServers), $NIC.SetDynamicDNSRegistration(“TRUE”)}

remotednschange2

About AJ McKean

Based in sunny Tauranga, New Zealand, AJ McKean is a Senior Systems Engineer in Mt Maunganui. With over 15 years of professional IT experience working in both New Zealand and the United States, he holds several certifications including MCSE(2000-2003), MCITP:Enterprise(2008), MCSA(2012), VMware VCP-DCV5.5, CompTIA A+ & is an HP Storage Architect. He is passionate about all things IT, especially virtualization, automation & cloud technologies.

2 Responses to “Remotely set DNS Primary and Secondary Servers via PowerShell”

  1. Matt says :

    Will this work for server 2003 as well?

    • AJ McKean says :

      Off the top of my head, I don’t believe PS remoting is support in 2k3 so I don’t believe you could. Something like PSEXEC \\computername netsh interface ip set address name=”Local Area Connection” static 8.8.8.8 could potentially work. You could feed \\computername in has a variable from the get-content list with a foreach statement.

Leave a Reply

Your email address will not be published. Required fields are marked *