JMMLAN
asked on
Using a script to map multiple drives based on group membership
Good Afternoon,
I have a very limted knowledge of scrupting using VBS however I was able to piece together the below script but it will only map a single network drive
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo ")
Set objNetwork = CreateObject("Wscript.Netw ork")
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 "AOD Users"
objNetwork.MapNetworkDrive "M:", "\\QPRCAOD01\AOD"
End Select
Next
How can I expand on this so that it will map more than one drive> For example I would like to map up to five different drive letters using one script. One drive would map to M, one to S, one to T, and another to H. A user who is a mamber for the drives M,S, and T would get those drives only but not the T abd H drives.
Any help would be appreciated
I have a very limted knowledge of scrupting using VBS however I was able to piece together the below script but it will only map a single network drive
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo
Set objNetwork = CreateObject("Wscript.Netw
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 "AOD Users"
objNetwork.MapNetworkDrive
End Select
Next
How can I expand on this so that it will map more than one drive> For example I would like to map up to five different drive letters using one script. One drive would map to M, one to S, one to T, and another to H. A user who is a mamber for the drives M,S, and T would get those drives only but not the T abd H drives.
Any help would be appreciated
ASKER
The code above works perfectly for mapping a single drive however I do not know how to expand it to add additiaonal drives based on membership in a group.
I'm sorry, I misunderstood your question - what you've got so far is so close the complete I assumed you cut a chunk out for brevity's sake.
All you need to do is add additional Case clauses to the Select Case block. In the example below I also forced strGroupName to lower case for the sake of comparison.
All you need to do is add additional Case clauses to the Select Case block. In the example below I also forced strGroupName to lower case for the sake of comparison.
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 = LCase(objGroup.CN)
Select Case strGroupName
Case "aod users"
objNetwork.MapNetworkDrive "M:", "\\QPRCAOD01\AOD"
Case "group number 2"
objNetwork.MapNetworkDrive "N:", "\\Server\Group2Share"
Case "group 3"
objNetwork.MapNetworkDrive "O:", "\\Server\3rdShare"
End Select
Next
ASKER
Ok I added additional cases and for testing sake I am a member of AOD Users and Domain Users but I only map the drive for AOD Users. Here is what I used:
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo ")
Set objNetwork = CreateObject("Wscript.Netw ork")
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 "Abra Users"
objNetwork.MapNetworkDrive "H:", "\\QPRCDATA01\Abra Suite"
Case "AOD Users"
objNetwork.MapNetworkDrive "M:", "\\QPRCAOD01\AOD"
Case "Resource Users"
objNetwork.MapNetworkDrive "R:", "\\QPRCDATA01\Resource"
Case "Domain Users"
objNetwork.MapNetworkDrive "S:", "\\QPRCDATA01\Folders Shared Across Departments"
Case "Domain Users"
objNetwork.MapNetworkDrive "T:", "\\QPRCDC01\DC01Shared"
End Select
Next
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo
Set objNetwork = CreateObject("Wscript.Netw
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 "Abra Users"
objNetwork.MapNetworkDrive
Case "AOD Users"
objNetwork.MapNetworkDrive
Case "Resource Users"
objNetwork.MapNetworkDrive
Case "Domain Users"
objNetwork.MapNetworkDrive
Case "Domain Users"
objNetwork.MapNetworkDrive
End Select
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok I did what you said with the Case which makes perfect sense and I removed the "On Error" piece. I am now in 3 groups...Abra Users, AOD Users, and Domain Users but I still only map M and I get nothing back in terms of an error message.
ASKER
THANK YOU...It works once I used it logging in
You could also add some MsgBox statements to check on the values of things like strGroupName while the script is running.