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:
#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”)}
Will this work for server 2003 as well?
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.