JSI Tip 10625. How can I change the subnet mask on all the workstations and member servers of my domain?

Jerold Schulman

July 4, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today

I have scripted MbrSNM.bat to change the subnet mask on all the workstations and member servers of the domain you are logged onto.

The syntax for using MbrSNM.bat is:

MbrSNM Interface NewSubnetMask Account Password

where:

Interface     is the name of the interface you wish to configure.NewSubnetMask is the new subnet mask for the Interface interface.Account       is an account that has administrative privileges on all members, like Administrator.Password      is the password for Account.

NOTE: MbrSNM.bat uses the following programs and scripts, which must be present in the PATH of the computer you use to run the script:

       NETDOM.EXE   from the Support Tools of your operating system CD-ROM.       NetSh.exe    see tip 10621 How can I display the IP configuration information for a specific interface?       PsExec.EXE   from tip 4141 PsExec freeware executes programs remotely.       CMPAvail.bat from tip 9825 Another way to test the availability of a remote computer.                    Because of CMPAvail.bat, you must run the MbrSNM.bat script from Windows XP,                    or Windows Server 2003, or later.

MbrSNM.bat contains:

@echo offif {%4}=={} @echo Syntax: MbrSNM Interface SubNetMask Account Password&goto :EOFsetlocalset Intrf=%1set NewSNM=%2set usr=%3set pw=%4set netdm=netdom query /domain:%userdnsdomain% workstationset fnd=FIND /i /v "The command completed successfully."@echo.setlocal>"%TEMP%MbrSNM.bat"@echo.set IP=NONE>>"%TEMP%MbrSNM.bat"@echo.for /f "Tokens=3 Delims=: " %%%%a in ('netsh interface ip show config %intrf%^^^|find "IP Address"') do (>>"%TEMP%MbrSNM.bat"@echo. set IP=%%%%a>>"%TEMP%MbrSNM.bat"@echo.)>>"%TEMP%MbrSNM.bat"@echo.netsh interface ip set address %Intrf% static %%IP%% %NewSNM%>>"%TEMP%MbrSNM.bat"@echo.endlocal>>"%TEMP%MbrSNM.bat"for /f "Skip=1 Tokens=*" %%C in ('%netdm%^|%fnd%') Do call :mbr1 %%Cif exist "%TEMP%MbrSNM.tmp" del /q "%TEMP%MbrSNM.tmp"if exist "%TEMP%MbrSNM.bat" del /q "%TEMP%MbrSNM.bat"endlocalgoto :EOF:mbr1call CMPAvail %1 OKif "%OK%" EQU "Y" goto mbr2@echo Computer %1 is not available.goto :EOF:mbr2set cmp=\%1if exist "%TEMP%MbrSNM.tmp" del /q "%TEMP%MbrSNM.tmp"call :mbr3>nul 2>&1if not exist "%TEMP%MbrSNM.tmp" goto :EOFset GOOD=Nfor /f "Tokens=*" %%x in ('type  "%TEMP%MbrSNM.tmp"^|find "Ok."') do ( set GOOD=Y)@echo "%cmp%","%GOOD%"if exist "%TEMP%MbrSNM.tmp" del /q "%TEMP%MbrSNM.tmp"goto :EOF:mbr3psExec %cmp% -u %usr% -p %pw% -c "%TEMP%MbrSNM.bat">"%TEMP%MbrSNM.tmp"



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like