- notageek.it di Mirko Iodice - http://www.notageek.it -

Remotely Change IP Gateway DNS and WINS

Questo script permette di modificare da remoto tutti i principali parametri di configurazione assegnati ad una scheda di rete: Indirizzo IP, Subnet Mask, Default Gateway, suffisso DNS specifico per la connessione, server DNS Primario e secondario, server WINS primario e secondario.

E' necessario impostare tutte le variabili contenute nella sezione ' -------- Set variables here -------- del codice sorgente.

Potete eseguirlo indifferentemente con entrambi i motori WSH ("wscript.exe" oppure "cscript.exe").

'------------------- Declarations
dim aDNS(1)
Dim strWINS1
Dim strWINS2
dim strComputer
dim objWMIService
dim errDNS
dim errWINS
dim errEnable
dim errGateways
dim errDNSDomain
dim objItem 
dim colItems
'---------------------------------

' -------- Set variables here --------

' Set Computer Name or IP Address to run against
strComputer = "PC1"

' Set IP - Subnet - Gateway to assign
strIPAddress = Array("192.168.0.1")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.0.254")
strGatewaymetric = Array("1")

' Set DNS servers in search order to assign - or leave them blank
aDNS(0) = "208.67.222.222"
aDNS(1) = "208.67.220.220"

' Set connection-specific DNS suffix to assign - or leave it blank
dnsdomain = "domain.lan"

' Set WINS servers in search order to assign - or leave them blank
strWINS1 = ""
strWINS2 = ""

' -------- Variables End --------

On error resume next
set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = 1")
For Each objItem in colItems
	errDNS = objItem.SetDNSServerSearchOrder()
	errDNS = objItem.SetDNSServerSearchOrder(aDNS)
	errWINS = objItem.SetWINSServer (strWINS1,strWINS2)
	errDNSDomain = objItem.SetDNSDomain (dnsdomain)
	errGateways = objItem.SetGateways(strGateway, strGatewaymetric)
	errEnable = objItem.EnableStatic(strIPAddress, strSubnetMask)
Next

set objWMIService = Nothing
set colItems = Nothing

msgbox("Done")