JSI Tip 4905. An alternative to the Ifmember command

Jerold Schulman

February 28, 2002

1 Min Read
ITPro Today logo


I find that the Windows 2000 Resource Kit is an indispensable tool for managing a Windows 2000 environment.

The Windows 2000 Server Resource Kit Supplement One is a CD-ROM that contains all the server and Professional tools, as well as the online documentation for both Server and Professional.

Microsoft has some Windows 2000 Resource Kit utilities in the public domain, but even if all the tools were available, the help files, registry, policy, and event references would make this CD-ROM anvaluable acquisition.

In tip 4630, I scripted an alternative to the Sleep command.

"IfMember is a command-line tool that checks whether the current user is a member of a specified group. It is typically used in Windows logon scripts and other batch files.

IfMember uses its own process token to discover group membership, rather than querying the relevant domain controller each time it runs. While this has a significant performance benefit, it does mean that IfMember will only be aware of groups on the local computer, on the computer's domain, and on trusted domains."

I have scripted two alternatives to the Ifmember tool, IsLocal.bat and IsDomain.bat. The syntax is:

IsDomain UserName DomainGroup

IsLocal UserName LocalGroup

Both scripts return a $Member environment variable, which is set to Y or N.

Sample Usage:

call IsDomain "%userName%" "Domain Admins"
if "%$Member%" EQU "Y" goto UserIsDomainAdmin

call IsLocal "%username%" "Administrators"
if "%$Member%" EQU "Y" goto UserIsLocalAdministrator

call IsLocal Jerry Administrators
if "%$Member%" EQU "Y" goto UserIsLocalAdministrator

IsDomain.bat contains:

@echo offset $Member=Nif {%2}
{} goto :EOFnet user %1 /domain | find /i %2 >nulif not errorlevel 1 set $Member=Y

IsLocal.bat contains:

@echo offset $Member=Nif {%2}{} goto :EOFnet user %1 | find /i %2 >nulif not errorlevel 1 set $Member=Y



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