Check User or Computer Group membership in logon script

As an administrator, we put users into user groups all the time.  In my experience, however,  we rarely put  computers into computer groups.  Computer groups are a great way to control the user’s logon script and batch installations, especially for patch restricted or other special  systems.  There are a number of tools that allow you to check the current user’s membership in a group.  Some scripts are available, see: http://www.petri.co.il/forums/showthread.php?t=26882, but I was unable to find a tool for computer group membership for batch files, so I wrote isMember.vbs.  This script checks the membership of the current user or computer in a group. It is designed to be run in a batch file, and sets an errorlevel on exiting. 

Example: cscript isMember.vbs /user “Accounting Execs”
Example: cscript isMember.vbs /computer “Patch restricted PCs”

Note: If the group name contains a space, it must be in quotations.

ERRORLEVELs: 1 if isMember is true, 0 if isMember is false, 100 if group does not exist.

Batch file example:

cscript ismember.vbs /user SomeUserGroup
if %errorlevel% == 100 echo group not found
if %errorlevel% == 1 echo Member
if %errorlevel% == 0 echo Not a Member

As always, rename from .txt to .vbs.

 

Tags: isMember, Group+Membership

About Alan

See http://www.akaplan.com/blog/about/
This entry was posted in Computing, Scripting, VbScript, Windows Administration and tagged . Bookmark the permalink.

Leave a Reply