Mapping Drives by Group

Posted: May 1, 2010 in Logon Script with Shell
Tags:


Mapping drives by group membership allows you to control which drives and resources will be available to which users. The resource kit utility IfMember allows you to determine a user’s group membership from the command line. The basic syntax of the IfMember utility is as follows:

IfMember /Commands Groups

Here, Groups are any group, separated by spaces, whose membership you want to check. An errorlevel of 1 indicates the user is a member of the specified group. The available commands are as follows:

  • /List—Lists all groups the user belongs to
  • /Verbose—Displays all group matches

To map a network drive according to group membership and display the status from the command prompt, proceed as follows:

  1. Create a new directory to store all files included in this example.
  2. Select Start|Run and enter “scriptfile.bat.”

Here, scriptfile is the full path and file name of a script file that contains the following:

@Echo Off

CLS ; Clears the screen

Fullpath\IfMember GroupName > Nul

If Not %errorlevel% EQU 1 Goto End

Set Drive=DriveLetter

Set Share=\\server\sharename

Echo Mapping drive %Drive% to %Share%

Net Use %Drive%: /Delete && CLS

Net Use %Drive%: %Share%

If %errorlevel% EQU 0 CLS && Echo Map Successful && Goto End

CLS && Echo Error mapping drive %Drive% to %Share%

:End

Here, fullpath is the full path where the IfMember utility is located; GroupName is the name of the group to check membership; driveletter is the drive letter to map a share to; NEQ is the “not equal to” operator; EQU is the “equal to” operator; server contains the sharename you want to map to; and && allows you to run a second command after the first has completed.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s