Hi,
After removing a domain controller from a Domain recently I had to remove the old DNS ip address from all the clients.
For DHCP clients this is fairly easy and just needs to be updated in the DHCP server however statically set IP settings are not so straight forward.
First lets get a list of computer objects we are interested in (You can customize to your requirements)…
$day = (Get-Date).AddDays(-14) $comps = get-adcomputer -Filter {OperatingSystem -like "*Server*" -AND Lastlogondate -gt $day}
This will list all server OS machines last logged in within 2 weeks. It will show their IP and their DNS server search scope. This is just used to gather information and can be customized as needed.
ForEach ($comp in $comps) { $comp.Name $temp = get-wmiobject -class Win32_NetworkAdapterConfiguration -filter "IPEnabled = 'True'" -ComputerName $comp.Name @PSBoundParameters $temp.ipaddress $temp.DNSServerSearchOrder }
I would recommend reviewing the list manually and confirming what servers you need to change. To change a single server you can do the following command,
First set your new DNS server list,
$ips = "192.168.1.1","192.168.1.2"
Then this line will change one computer.
(get-wmiobject -class Win32_NetworkAdapterConfiguration -filter "IPEnabled = 'True'" -ComputerName COMPUTER1 @PSBoundParameters).setDNSServerSearcdOrder($ips)
Alternatively you can simply change all machines (I would avoid changing domain controllers and any machines that are getting their DNS settings from DHCP)
ForEach ($comp in $comps) { (get-wmiobject -class Win32_NetworkAdapterConfiguration -filter "IPEnabled = 'True'" -ComputerName $comp.Name @PSBoundParameters).setDNSServerSearcdOrder($ips) }
If you have a list of names in an array of strings,
$comps="COMPUTER1","COMPUTER2","COMPUTER3"
Then change the command to remove the .Name like so,
ForEach ($comp in $comps) { (get-wmiobject -class Win32_NetworkAdapterConfiguration -filter "IPEnabled = 'True'" -ComputerName $comp @PSBoundParameters).setDNSServerSearcdOrder($ips) }
Hopefully that will help someone.