In my enviroment i have several forests that are setup as different domains. We are currently in the process of upgrading our DC's to 2012, these will also be my DNS servers. My servers have different NIC's that go to different subnets. I need to change the DNS servers only on the NIC's that have a certain DNS server on them. I am changing the dns on several servers from the DC and using a txt file for my server list. I am trying to use an IF statement in my script to define the old DNS server and tell the script to only change DNS servers on these NIC's. I do not want to change the DNS on the other NIC's because they go to different subnets, some like my backup network do not even use DNS servers. The script as i have it will change all the DNS servers on all the NIC's on the servers. Why is my IF statement not working?
Thanks in advance for your time and assistance.
$OldDNS = 192.168.10.47
$computer = get-content C:\computers\computers.txt
$NICs = Get-WMIObject Win32_NetworkAdapterConfiguration -computername $computer |where{$_.IPEnabled -eq “TRUE”}
Foreach($NIC in $NICs) {if($_.DNSServerSearchOrder -match $OldDNS ){$_.DNSServerSearchOrder}
$DNSServers = “198.168.10.125",”198.168.10.126"
$NIC.SetDNSServerSearchOrder($DNSServers)
$NIC.SetDynamicDNSRegistration(“TRUE”)
}Thanks for your help