I need help writing a VBS script that changes ONLY the subnet mask for 200 computers in my domain.

My network consists of a Server 2003 servers, W2K, and XP clients. I have around 200 PCs where I need to change the subnet mask so I can move forward with configuring a trust on the Domain Controller. I have a script that is able to change everything: IP, Subnet, and Gateway. My issue is that I don't need to change the IP or gateway, just subnet mask. The script I'm using does not allow for only one of the three items to change. If I take away one of the options, it errors. Can someone help providing scripting syntax that leaves the static IP as what it is, but only changes the subnet mask? Here's what I have so far...

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
s1979Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rejoinderCommented:
This will keep the IP settings and carry them over as it updates the subnet mask.
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
 
Set colNetAdapters = objWMIService.ExecQuery _
    ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
 
strSubnetMask    = Array("255.255.255.0")
strGateway       = Array("192.168.1.100")
strGatewayMetric = Array(1)
 
For Each objNetAdapter in colNetAdapters
    arrIPAddress  = objNetAdapter.IPAddress
    'arrDNSSetting = objNetAdapter.DNSServerSearchOrder
    errEnable     = objNetAdapter.EnableStatic(arrIPAddress, strSubnetMask)
    errGateways   = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
    'errDNSSetting = objNetAdapter.SetDNSServerSearchOrder(arrDNSSetting)
    Select Case errEnable
        Case 0
            wscript.echo "Successful completion, no reboot required."
        Case 1
            wscript.echo "Successful completion, reboot required."
        Case 64
            wscript.echo "Method not supported on this platform."
        Case 65
            wscript.echo "Unknown failure."
        Case 66
            wscript.echo "Invalid subnet mask."
        Case 67
            wscript.echo "An error occurred while processing an instance that was returned."
        Case 68
            wscript.echo "Invalid input parameter."
        Case 69
            wscript.echo "More than five gateways specified."
        Case 70
            wscript.echo "Invalid IP address."
        Case 71
            wscript.echo "Invalid gateway IP address."
        Case 72
            wscript.echo "An error occurred while accessing the registry for the requested information."
        Case 73
            wscript.echo "Invalid domain name."
        Case 74
            wscript.echo "Invalid host name."
        Case 75
            wscript.echo "No primary or secondary WINS server defined."
        Case 76
            wscript.echo "Invalid file."
        Case 77
            wscript.echo "Invalid system path."
        Case 78
            wscript.echo "File copy failed."
        Case 79
            wscript.echo "Invalid security parameter."
        Case 80
            wscript.echo "Unable to configure TCP/IP service."
        Case 81
            wscript.echo "Unable to configure DHCP service."
        Case 82
            wscript.echo "Unable to renew DHCP lease."
        Case 83
            wscript.echo "Unable to release DHCP lease."
        Case 84
            wscript.echo "IP not enabled on adapter."
        Case 85
            wscript.echo "IPX not enabled on adapter."
        Case 86
            wscript.echo "Frame or network number bounds error."
        Case 87
            wscript.echo "Invalid frame type."
        Case 88
            wscript.echo "Invalid network number."
        Case 89
            wscript.echo "Duplicate network number."
        Case 90
            wscript.echo "Parameter out of bounds."
        Case 91
            wscript.echo "Access denied."
        Case 92
            wscript.echo "Out of memory."
        Case 93
            wscript.echo "Already exists."
        Case 94
            wscript.echo "Path, file, or object not found."
        Case 95
            wscript.echo "Unable to notify service."
        Case 96
            wscript.echo "Unable to notify DNS service."
        Case 97
            wscript.echo "Interface not configurable."
        Case 98
            wscript.echo "Not all DHCP leases could be released or renewed."
        Case 100
            wscript.echo "DHCP not enabled on adapter."
    end select
Next
 
wscript.echo "Done."

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
s1979Author Commented:
Thank you very much! You've helped me save the day!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.