
Change DNS servers on the stations using a script
This is useful when we are performing a server migration, in the event that we are going to change the IP address DNS servers or the server DNS server, we must change its DNS servers in all positions. The posts may be configured with a dynamic IP address so the change is very simple and we will change it only on the DHCP server. But.. What happens if our posts have a fixed IP address? That we should change the 'Preferred DNS Server'’ and the 'Alternate DNS Server'’ or manually or with the help of a simple script that we can put in the login of the posts through a GPO.
The script in question is as follows:
This would be the script to run on the client endpoints:
On Error Resume Next
strComputer = “.”
Set objWMIService = GetObject(“Winmgmts:” _
& “{impersonationLevel=impersonate}!” & strComputer & “rootcimv2”)
Set colNetCards = objWMIService.ExecQuery _
(“Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True”)
For Each objNetCard in colNetCards
arrDNSServers = Array(“DIRECCION_IP_SERVIDOR_DNS_1”, “DIRECCION_IP_SERVIDOR_DNS_2”)
objNetCard.SetDNSServerSearchOrder(arrDNSServers)
Next
This will change the two DNS servers if we have a fixed IP address, If it's only one, It's a matter of modifying the script.
www.bujarra.com – Héctor Herrero – Nh*****@bu*****.cOm – v 1.0