VB Script will not map drives based on group membership

I have a VB Script that will not map a drive, unless the person is a member of at least 3 groups in Active Directory. For example, by default they are a member of "Domain Users", then I will add them to "Accounting". The script will not recognize that they are a member of Accounting and map a drive letter until I add them to another group in Active Directory.

Any help would be great!

For Each strGroup in objUser.MemberOf 'Walk through the groups that user is a member of strGroupPath = "LDAP://" & strGroup Set objGroup = GetObject(strGroupPath) 'Bind to the group in Active Directory strGroupName = objGroup.CN 'Get the group name strGroupName = lcase(strGroupName) 'Set group name to all lowercase'-------------------------------------BY GROUP--------------------------------------------------------------------'----------------------------------------------------------------------------------------------------------------- Select Case strGroupName Case "hr" 'If in this group map the drive on next line objNetwork.MapNetworkDrive "R:", "\\chdifs01\hr$" Case "accounting" 'If in this group map the drive on next line objNetwork.MapNetworkDrive "Q:", "\\chdifs01\accounting$" Case "mis" 'If in this group map the drive on next line objNetwork.MapNetworkDrive "m:", "\\chdifs01\mis$" End Select

One more thing, if it's echoing back exactly what you have, but drives are STILL not mapping, add a wscript.echo statement within each of the cases. That will prove it's entering the appropriate statement, but it's the actual mapping command that's failing, not the case.

Firstly, "Domain Users" is a primary group, and is not enumerated by the MemberOf property, so it doesn't count as a group membership in this case. Secondly, objUser.MemberOf is a String data type if the user is only a member of one other group (so it shows 2 in the GUI). For this reason, the For Each strGroup In objUser.MemberOf statement does not work, because you need an array. So, that's why, only when you add a second group (3 in the GUI), objUser.MemberOf becomes an array of group names, so the For Each *does* work.

So, I've changed your script a bit. I have first checked the TypeName, to determine whether objUser.MemberOf is "Empty", a "String", or an "Array". Then, we don't need to bind to the group to get the group name. The format of strGroup comes out as
CN=GroupName,OU=MyOU,DC=domain,DC=com

so we know the first part of that is the group name. We use the Split function to split by the comma, so that element zero is the group name, then we use the Mid function to return the rest of the string after (and including) character 4. So that this
strGroupName = Mid(Split(strGroup, ",")(0), 4)

returns just GroupName.

Then I changed your Select Case statement to a sub, so you can call it from anywhere, and don't have to duplicate it.

I hope that helps.

Regards,

Rob.

If TypeName(objUser.MemberOf) = "Empty" Then 'WScript.Echo "You are not a member of any groups."ElseIf TypeName(objUser.MemberOf) = "String" Then strGroupName = Mid(Split(objUser.MemberOf, ",")(0), 4) CheckGroup strGroupNameElse For Each strGroup In objUser.MemberOf 'Walk through the groups that user is a member of strGroupName = Mid(Split(strGroup, ",")(0), 4) 'Get the group name CheckGroup strGroupName NextEnd If'-------------------------------------BY GROUP--------------------------------------------------------------------'-----------------------------------------------------------------------------------------------------------------Sub CheckGroup(strGroupName) Set objNetwork = CreateObject("WScript.Network") Select Case LCase(strGroupName) Case "hr" 'If in this group map the drive on next line objNetwork.MapNetworkDrive "R:", "\\chdifs01\hr$" Case "accounting" 'If in this group map the drive on next line objNetwork.MapNetworkDrive "Q:", "\\chdifs01\accounting$" Case "mis" 'If in this group map the drive on next line objNetwork.MapNetworkDrive "m:", "\\chdifs01\mis$" End SelectEnd Sub

Ha ha! Thanks....I have learnt most things the hard way though...plenty of hair pulling when things don't go right....plenty of research, and most of the stuff I know has come from writing things here for others.

Nah, my weekend is over now.....7:45 am here on Monday morning....although, I did look at EE over the weekend....I must be sick! LOL!

OK, I saw your Refresh problem....I think the timer will work, I've used that before....I'll have to wait till I get to work in an hour or so to check that out though...

That's good. So that's the same code that I posted just before.....strange that it didn't work the first time.

Anyway, so we know that the For loop *is* working, so now you should be able to add the CheckGroup sub to the bottom of that code, uncomment the CheckGroup strGroupName lines, and it should map the drives.

Welcome back! My apologies for taking so long to write part two of this series; it's been a long time coming! As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for. Why is this us…

Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video.
If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …