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.
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 Next Have a question? Need help? Get free, friendly person-to-person help with your computer questions or spyware questions in our help forums! |