JSI Tip 10001. How can a script determine if the computer it is running on is a Standalone Workstation, Member Workstation, Standalone Server, Member Server, Backup Domain Controller, or Primary Domain Controller?

Jerold Schulman

December 22, 2005

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

I have scripted DomainRole.bat to determine which of the following roles describes the current computer:

Standalone WorkstationMember WorkstationStandalone ServerMember ServerBackup Domain ControllerPrimary Domain Controller

The syntax for using DomainRole.bat is:

call DomainRole string

Where string is a call directed environment variable that will contain one of the following number-text strings:

0-Standalone Workstation1-Member Workstation2-Standalone Server3-Member Server4-Backup Domain Controller5-Primary Domain Controller

DomainRole.bat contains:

@echo offif {%1}=={} @echo Syntax: DomainRole Role&goto :EOFsetlocalif exist "%TEMP%DoomainRole.vbs" goto doit@echo On Error Resume Next>"%TEMP%DoomainRole.vbs"@echo strComputer = ".">>"%TEMP%DoomainRole.vbs"@echo Set objWMIService = GetObject("winmgmts:\" ^& strComputer ^& "rootcimv2")>>"%TEMP%DoomainRole.vbs"@echo Set colItems = objWMIService.ExecQuery("Select DomainRole from Win32_ComputerSystem",,48)>>"%TEMP%DoomainRole.vbs"@echo For Each objItem in colItems>>"%TEMP%DoomainRole.vbs"@echo.  Wscript.Echo objItem.DomainRole>>"%TEMP%DoomainRole.vbs"@echo Next>>"%TEMP%DoomainRole.vbs":doitfor /f "Tokens=*" %%r in ('cscript //nologo "%TEMP%DoomainRole.vbs"') do ( set /a role=1%%r -10)set /a role=%role% * 28set table=0-Standalone Workstation    1-Member Workstation        2-Standalone Server         3-Member Server             4-Backup Domain Controller  5-Primary Domain Controller #call set work=%%table:~%role%^,28%%#set work=%work:  =%set work=%work: #=%set work=%work:#=%endlocal&set %1=%work%



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