gream0604 Posted February 8, 2011 Posted February 8, 2011 (edited) Hi all, We are in the process of changing our subnet mask, in order to bring in a new network range onto the site. I have written a script that changes only the subnet mask, but i have come to a problem. Most of the clients are on static ip address because of some of the software that we run. Some are on DHCP. In the script i want to exclude it from changing any ip addresses that are assigned by DHCP, as at the moment it takes the DHCP assigned address, and turns it into a static one! Any help would be much appreciated? Code below ------------------------ strComputer = "LocalHost" strUser = "VOSPERS\Administrator" strPassword = "" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colNetAdapters = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") strSubnetMask = Array("255.255.254.0") For Each objNetAdapter in colNetAdapters strIPAddress = objNetAdapter.IPAddress strGateway = objNetAdapter.DefaultIPGateway strGatewayMetric = objNetAdapter.GateWayCostMetric 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 has been changed." End If Next Edited February 8, 2011 by gream0604
CJF Posted February 8, 2011 Posted February 8, 2011 Hi Gream0604, Why don't you use static leases in your dhcp pool? I'm guessing you already know which have static addresses at the moment, just get their mac addresses and hand out their reservations in dhcp. Also, I hope that isn't your actual admin password in your script
gream0604 Posted February 8, 2011 Author Posted February 8, 2011 Hi CJF, Whoops. I have removed it now!! I have sorted it now. The new script reads: -------------------------------------------------------- strComputer = "LocalHost" strUser = "VOSPERS\Administrator" strPassword = "password" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colNetAdapters = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") strSubnetMask = Array("255.255.254.0") For Each objNetAdapter in colNetAdapters If objnetadapter.DHCPEnabled = True Then wscript.quit else strIPAddress = objNetAdapter.IPAddress strGateway = objNetAdapter.DefaultIPGateway strGatewayMetric = objNetAdapter.GateWayCostMetric 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 has been changed." End If End If
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now