Free Computer Help.
Powered by Volunteers.

Map Network Drive based on Group Membership

by Oscar Sodani
June 19, 2008

Oscar Sodani is a founder of Help2Go and owner of Help2Go Networks, an IT consulting firm in the Washington D.C. area. Oscar holds the CISSP certification as well as industry certifications from Microsoft, Cisco and Novell.

I have to admit, this was driving me a little nuts. All I needed was a VB Script that would map a network drive for a user based on which groups they belong to in a Windows 2003 Server Active Directory. Simple, right? Yet, the numerous examples I found on the 'net didn't work correctly. Finally, I found one that worked for me, so I'll share it here.


One caveat, however: the user must belong to at least 2 groups for this to work. What I did was to make sure that all my users were in a generic Domain Users group first, or create your own generic group for everyone. The reason for this is that the script expects the number of group memberships to be greater than 1.

 Here is the relevant part of the script I am now using (simply replace the group names, share names, and server name with your own):


On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")

strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)

For Each strGroup in objUser.MemberOf
    strGroupPath = "LDAP://" & strGroup
    Set objGroup = GetObject(strGroupPath)
    strGroupName = objGroup.CN

Select Case strGroupName
    Case "JuniorHigh"
        objNetwork.MapNetworkDrive "J:", "\\SERVERNAME\JuniorHighShare"

    Case "HighSchool"
        objNetwork.MapNetworkDrive "K:", "\\SERVERNAME\HighSchoolShare"

    Case "LowerSchool"
        objNetwork.MapNetworkDrive "L:", "\\SERVERNAME\LowerSchoolShare"

End Select


Have a question? Need help? Get free, friendly person-to-person help with your computer questions or spyware questions in our help forums!

Creative Commons License

(C) 2008 Help2Go - Contact Us