Alan's Blog

"Yeah. I wrote a script that will do that."

Check User or Computer Group membership in logon script

Posted on May 22nd, 2009

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:, 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

Filed under Computing, Scripting, VbScript, Windows Administration | No Comments »

Please Note

All the scripts are saved as .txt files. Newer files have a "View Script" button which will let you save or open a script in notepad. For earlier posts, the easiest way to download with IE is to right click on the link and use "Save Target As". Rename file from Name_ext.txt to Name.ext.

To see a full post after searching, please click on the title.

PowerShell Scripts were written with Version 3 or 4.

https connections are supported.

All new users accounts must be approved, as are comments. Please be patient. It is pretty easy to figure out my email address from the scripts, and you are welcome to contact me that way.

Site Search



SQL Site

Bad Behavior has blocked 262 access attempts in the last 7 days.