|
server
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Changing Ip addresses in script?
Hello All,
We are in the middle of deploying a new network infrastructure with new subnet ids. Is there a way that I can run a logon script to change values for IP addresses/gateways, dns, etc. Moreover, if that cannot be done I am planning to deploy a DHCP server, so maybe there is a way to reset nic to use DHCP rather than static ips which all machines in this environment currently are configured as. Any suggestions, TIA, Altria BTW, running Win2k3 server with xpsp2 clients.. I have attempted to use the netsh command in a script to do some of
what you are asking. In the following example it only works if the network port that is active is named "Local Area Connection". I'm sure there are more elegant ways to do this but I have found it to work. ----------------------------------------------------------------- Set objShell = CreateObject("Wscript.Shell") strTCP = xxx.xxx.xxx.xxx strMask = xxx.xxx.xxx.xxx strgwy = xxx.xxx.xxx.xxx strDNS1 = xxx.xxx.xxx.xxx strDNS2 = xxx.xxx.xxx.xxx strWins1 = xxx.xxx.xxx.xxx strWins2 = xxx.xxx.xxx.xxx objshell.Run _ ("%comspec% /c netsh -c ""interface ip"" set address ""local area connection"" static " _ & strTCP & " " & strMask & " " & strgwy & " 1"),,True objshell.Run _ ("%comspec% /c netsh -c ""interface ip"" add dns ""local area connection"" " _ & strDNS1 & " 1"),,True objshell.Run _ ("%comspec% /c netsh -c ""interface ip"" add dns ""local area connection"" " _ & strDNS2 & " 2"),,True objshell.Run _ ("%comspec% /c netsh -c ""interface ip"" add wins ""local area connection"" " _ & strWins1 & " 1"),,True objshell.Run _ ("%comspec% /c netsh -c ""interface ip"" add wins ""local area connection"" " _ & strWins2 & " 2"),,True I have attempted to use the netsh command in a script to do some of
what you are asking. In the following example it only works if the network port that is active is named "Local Area Connection". I'm sure there are more elegant ways to do this but I have found it to work. ----------------------------------------------------------------- Set objShell = CreateObject("Wscript.Shell") strTCP = xxx.xxx.xxx.xxx strMask = xxx.xxx.xxx.xxx strgwy = xxx.xxx.xxx.xxx strDNS1 = xxx.xxx.xxx.xxx strDNS2 = xxx.xxx.xxx.xxx strWins1 = xxx.xxx.xxx.xxx strWins2 = xxx.xxx.xxx.xxx objshell.Run _ ("%comspec% /c netsh -c ""interface ip"" set address ""local area connection"" static " _ & strTCP & " " & strMask & " " & strgwy & " 1"),,True objshell.Run _ ("%comspec% /c netsh -c ""interface ip"" add dns ""local area connection"" " _ & strDNS1 & " 1"),,True objshell.Run _ ("%comspec% /c netsh -c ""interface ip"" add dns ""local area connection"" " _ & strDNS2 & " 2"),,True objshell.Run _ ("%comspec% /c netsh -c ""interface ip"" add wins ""local area connection"" " _ & strWins1 & " 1"),,True objshell.Run _ ("%comspec% /c netsh -c ""interface ip"" add wins ""local area connection"" " _ & strWins2 & " 2"),,True Try this
strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colNetAdapters = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") strIPAddress = Array("192.168.1.141") strSubnetMask = Array("255.255.255.0") strGateway = Array("192.168.1.100") strGatewayMetric = Array(1) For Each objNetAdapter in colNetAdapters errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) If errEnable = 0 Then WScript.Echo "The IP address has been changed." Else WScript.Echo "The IP address could not be changed." End If Next Show quote "Altria" <urbante***@msn.com> wrote in message news:eHRzYVHmFHA.576@TK2MSFTNGP15.phx.gbl... > Hello All, > We are in the middle of deploying a new network infrastructure with new > subnet ids. Is there a way that I can run a logon script to change values > for IP addresses/gateways, dns, etc. > Moreover, if that cannot be done I am planning to deploy a DHCP server, so > maybe there is a way to reset nic to use DHCP rather than static ips which > all machines in this environment currently are configured as. > > Any suggestions, > TIA, > Altria > > BTW, running Win2k3 server with xpsp2 clients.. > |
|||||||||||||||||||||||