Vbscript multiple groups not working, not working at all

I have the following logon script which worked ish using the if statement but not for mutilpe groups once it hit the first true statement it finished but then i read i shoudl be using select case but i cant get this to work at all, i'm new to vbs script which you'll probably see, attached code
Const information_systems   = "cn=information systems"
Const accounts		    = "cn=accounts"
Const chs_cleared_access    = "cn=chs cleared access"
Const north                 = "cn=north"
Const south                 = "cn=south"
Const north_east            = "cm=north east"
 
ON ERROR RESUME NEXT
 
Set wshNetwork = CreateObject("WScript.Network")
 
	Set clDrives = WshNetwork.EnumNetworkDrives
	For i = 0 to clDrives.Count -1 Step 2
	WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
 
	Next 
 
	wscript.sleep 300
 
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.MemberOf))
Set objGroup = GetObject(StrGroupPath)
strGroupName = LCase(objGroup.CN)
 
 
'If InStr(strGroups, information_systems) Then
 
select case strGroupName
 
	case "information systems"
 
		wshNetwork.MapNetworkDrive "R:","\\ukchsc01ds01\datasuite"
		wshNetwork.MapNetworkDrive "U:","\\Ukchsc01ds01\distributionNet"
		wshNetwork.MapNetworkDrive "V:","\\Ukchsc01es01\clientapps"
		wshNetwork.MapNetworkDrive "w:","\\Ukchsc01es01\serverApps"
 
'ElseIf InStr(strGroups, accounts) Then
 
	Case "accounts"
 
		wshNetwork.MapNetworkDrive "R:","\\ukchsc01ds01\datasuite"
		wshNetwork.MapNetworkDrive "T:","\\ukchsc01ds01\companyaccounts"
		wshnetwork.MapnetworkDrive "S:","\\ukchsc01ds01\companyadmin"
 
'ElseIf InStr(strGroups, chs_cleared_access) Then
 
	Case "chs cleared access"
 
		wshNetwork.MapNetworkDrive "R:","\\ukchsc01ds01\datasuite"
 
 
'ElseIf InStr(strGroups, north) Then
 
	Case "north"
 
		WshNetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4650"
		wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hpdesignjet"
		wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hp2840"
		wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Stores"
		wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Directors"
		wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4730-office"
		WshNetwork.SetDefaultPrinter "\\ukchsc01es01\hp4650"
 
'ElseIf InStr(strGroups, south) Then
 
	Case "south"
 
		WshNetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4650"
		wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hpdesignjet"
		wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hp2840"
		wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Stores"
		wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Directors"
		wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4730-office"
		WshNetwork.SetDefaultPrinter "\\ukchsc01es01\hp4730-office"
 
'ElseIf InStr(strGroups, north east) Then
 
	Case "north_east"
 
		WshNetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4650"
		wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hpdesignjet"
		wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hp2840"
		wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Stores"
		wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Directors"
		wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4730-office"
		WshNetwork.SetDefaultPrinter "\\ukchsc01es01\hp2600-Directors"
 
End select

Open in new window

LVL 1
CHSCLMAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

piattndCommented:
Comment out "on error resume next", run the script on a test account, and give the results.  Is there a runtime error?  If so, what line/chr?

If no runtime error, does nothing map?
0
piattndCommented:
Also, add an echo on your variable strGroupName.  Make sure the echo represents the exact phrase you're using inside your "case" statements.
0
CHSCLMAuthor Commented:
says error line 23 cha 1?

Sorry add echo could you explain that,?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

piattndCommented:
so just before your select case strGroupName statement, add:

wscript.echo strGroupName

What is the error it's saying at 23 cha1?
0
piattndCommented:
Is this your whole entire login script or is this only a function within your login script?  On line 23 you're trying to set objgroup to a "GetObject" when you haven't defined the variable contents... are you defining that in a different sub?
0
CHSCLMAuthor Commented:
this is the whole script, i've copy and pasted from examples. do i need to remove that?

the idea of it is to map the drives and printers according to the groups and thats it.
0
piattndCommented:
I'll modify the code that you've got up there, but yes it's got some loose ends.  I'm heading to lunch right now, I'll see what I can do once I get back.  Someone else might be able to do it sooner, so keep your eyes on this post.
0
RobSampsonCommented:
Hi, you can give this a shot.  CurrentUser.MemberOf, if I remember rightly, is empty if the user is not a member of any groups, a string if there is only one group, or an array if multiple groups.  So I've adjusted the code for that, and also moved the mapping to a sub, to check based on each group name.

Within that sub, I can't remember if you'll to add CN= to each of the group names to check or not....

To test, above each of these lines
      CheckGroup strGroup

you could add
      MsgBox "Checking for " & strGroup

and you'll see how the group is defined for the user.

Regards,

Rob.
Set wshNetwork = CreateObject("WScript.Network")
 
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
	WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next
wscript.sleep 300
 
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
If TypeName(CurrentUser.MemberOf) = "Empty" Then
	'WScript.Echo CurrentUser.CN & " is not a member of any groups."
ElseIf TypeName(CurrentUser.MemberOf) = "String" Then
	strGroup = CurrentUser.MemberOf
	CheckGroup strGroup
Else
	For Each strGroup In CurrentUser.MemberOf
		CheckGroup strGroup
 	Next
End If
 
'If InStr(strGroups, information_systems) Then
 
Sub CheckGroup(strGroupName)
	Set wshNetwork = CreateObject("WScript.Network")
	select case strGroupName
	 
		case "information systems"
	 
			wshNetwork.MapNetworkDrive "R:","\\ukchsc01ds01\datasuite"
			wshNetwork.MapNetworkDrive "U:","\\Ukchsc01ds01\distributionNet"
			wshNetwork.MapNetworkDrive "V:","\\Ukchsc01es01\clientapps"
			wshNetwork.MapNetworkDrive "w:","\\Ukchsc01es01\serverApps"
	 
	'ElseIf InStr(strGroups, accounts) Then
	 
		Case "accounts"
	 
			wshNetwork.MapNetworkDrive "R:","\\ukchsc01ds01\datasuite"
			wshNetwork.MapNetworkDrive "T:","\\ukchsc01ds01\companyaccounts"
			wshnetwork.MapnetworkDrive "S:","\\ukchsc01ds01\companyadmin"
	 
	'ElseIf InStr(strGroups, chs_cleared_access) Then
	 
		Case "chs cleared access"
	 
			wshNetwork.MapNetworkDrive "R:","\\ukchsc01ds01\datasuite"
	 
	 
	'ElseIf InStr(strGroups, north) Then
	 
		Case "north"
	 
			WshNetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4650"
			wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hpdesignjet"
			wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hp2840"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Stores"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Directors"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4730-office"
			WshNetwork.SetDefaultPrinter "\\ukchsc01es01\hp4650"
	 
	'ElseIf InStr(strGroups, south) Then
	 
		Case "south"
	 
			WshNetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4650"
			wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hpdesignjet"
			wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hp2840"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Stores"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Directors"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4730-office"
			WshNetwork.SetDefaultPrinter "\\ukchsc01es01\hp4730-office"
	 
	'ElseIf InStr(strGroups, north east) Then
	 
		Case "north_east"
	 
			WshNetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4650"
			wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hpdesignjet"
			wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hp2840"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Stores"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Directors"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4730-office"
			WshNetwork.SetDefaultPrinter "\\ukchsc01es01\hp2600-Directors"
	 
	End Select
End Sub

Open in new window

0
CHSCLMAuthor Commented:
Thanks, i tried that out,

It didnt connect any drives i put the msgbox before the select case staement and it showed up if i put it inside the statement i.e when it should connect the drive it doesnt appear as if the script is bomming out before then?
0
rejoinderCommented:
I have modified a login script which will base the drive mapping and printers on the group membership of the user.

Let me know if you have any troubles running the script.
Set WSHNetwork = WScript.CreateObject("WScript.Network")
Set WSHShell = WScript.CreateObject("WScript.Shell")
 
On Error Resume Next
 
Domain = WSHNetwork.UserDomain
UserName = ""
 
While UserName = ""
	UserName = WSHNetwork.UserName
	MyGroups = GetGroups(Domain, UserName)
	DisconnectDrives
Wend
 
If INGROUP ("information systems") Then
	MapDrive "R:", "\\ukchsc01ds01\datasuite"
	MapDrive "U:", "\\Ukchsc01ds01\distributionNe"
	MapDrive "V:", "\\Ukchsc01es01\clientapps"
	MapDrive "W:", "\\Ukchsc01es01\serverApps"
End If
 
If INGROUP ("accounts") Then
	MapDrive "R:", "\\ukchsc01ds01\datasuite"
	MapDrive "T:", "\\ukchsc01ds01\companyaccounts"
	MapDrive "S:", "\\ukchsc01ds01\companyadmin"
End If
 
If INGROUP ("chs cleared access") Then
	MapDrive "R:", "\\ukchsc01ds01\datasuite"
End If
 
If INGROUP ("north") Then
	MapPrinter "\\ukchsc01es01\hp4650", "TRUE"
	MapPrinter "\\ukchsc01es01\hpdesignjet", "FALSE"
	MapPrinter "\\ukchsc01es01\hp2840", "FALSE"
	MapPrinter "\\ukchsc01es01\hp2600-Stores", "FALSE"
	MapPrinter "\\ukchsc01es01\hp2600-Directors", "FALSE"
	MapPrinter "\\ukchsc01es01\hp4730-office", "FALSE"
End If
 
If INGROUP ("south") Then
	MapPrinter "\\ukchsc01es01\hp4650", "FALSE"
	MapPrinter "\\ukchsc01es01\hpdesignjet", "FALSE"
	MapPrinter "\\ukchsc01es01\hp2840", "FALSE"
	MapPrinter "\\ukchsc01es01\hp2600-Stores", "FALSE"
	MapPrinter "\\ukchsc01es01\hp2600-Directors", "FALSE"
	MapPrinter "\\ukchsc01es01\hp4730-office", "TRUE"
End If
 
If INGROUP ("north_east") Then
	MapPrinter "\\ukchsc01es01\hp4650", "FALSE"
	MapPrinter "\\ukchsc01es01\hpdesignjet", "FALSE"
	MapPrinter "\\ukchsc01es01\hp2840", "FALSE"
	MapPrinter "\\ukchsc01es01\hp2600-Stores", "FALSE"
	MapPrinter "\\ukchsc01es01\hp2600-Directors", "TRUE"
	MapPrinter "\\ukchsc01es01\hp4730-office", "FALSE"
End If
 
 
Sub DisconnectDrives
	Set objDrives = WshNetwork.EnumNetworkDrives
	For i = 0 to objDrives.Count -1 Step 2
		WSHNetwork.RemoveNetworkDrive objDrives.Item(i), True, True
	Next
	wscript.sleep 300
End Sub
 
Function GetGroups(Domain, UserName)
	Set objUser = GetObject("WinNT://" & Domain & "/" & UserName)
	GetGroups=""
	For Each objGroup In objUser.Groups
		GetGroups=GetGroups & "[" & UCase(objGroup.Name) & "]"
	Next
End Function
 
Function InGroup(strGroup)
	InGroup=False
	If InStr(MyGroups,"[" & UCase(strGroup) & "]") Then
		InGroup=True
	End If
End Function
 
Sub MapDrive(sDrive,sShare)
	On Error Resume Next
	WSHNetwork.RemoveNetworkDrive sDrive, 1, 1
	WScript.Sleep 300
	Err.Clear
	WSHNetwork.MapNetworkDrive sDrive, sShare, 0
End Sub
 
Sub MapPrinter(sPrinterPath,sPrinterDefault)
	On Error Resume Next
	WSHNetwork.AddWindowsPrinterConnection sPrinterPath
	WScript.Sleep 300
	If sPrinterDefault = "1" Or sPrinterDefault = UCase("TRUE") Then
		WSHNetwork.SetDefaultPrinter sPrinterPath
	End If
End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobSampsonCommented:
OK, I just realised that each group is enumerated at
CN=Group Name,OU=Users,OU=TestOU,DC=domain,DC=com

so thats why the select case statement never matched anything.

So I've changed both instances of this line:
      CheckGroup strGroup

to this
      CheckGroup Mid(Split(strGroup, ",")(0), 4)

Which will now pass only the group name, without the CN= part, and other OU parts.

Regards,

Rob.
Set wshNetwork = CreateObject("WScript.Network")
 
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
	WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next
wscript.sleep 300
 
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
If TypeName(CurrentUser.MemberOf) = "Empty" Then
	'WScript.Echo CurrentUser.CN & " is not a member of any groups."
ElseIf TypeName(CurrentUser.MemberOf) = "String" Then
	strGroup = CurrentUser.MemberOf
	CheckGroup Mid(Split(strGroup, ",")(0), 4)
Else
	For Each strGroup In CurrentUser.MemberOf
		CheckGroup Mid(Split(strGroup, ",")(0), 4)
 	Next
End If
 
'If InStr(strGroups, information_systems) Then
 
Sub CheckGroup(strGroupName)
	Set wshNetwork = CreateObject("WScript.Network")
	select case strGroupName
	 
		case "information systems"
	 
			wshNetwork.MapNetworkDrive "R:","\\ukchsc01ds01\datasuite"
			wshNetwork.MapNetworkDrive "U:","\\Ukchsc01ds01\distributionNet"
			wshNetwork.MapNetworkDrive "V:","\\Ukchsc01es01\clientapps"
			wshNetwork.MapNetworkDrive "w:","\\Ukchsc01es01\serverApps"
	 
	'ElseIf InStr(strGroups, accounts) Then
	 
		Case "accounts"
	 
			wshNetwork.MapNetworkDrive "R:","\\ukchsc01ds01\datasuite"
			wshNetwork.MapNetworkDrive "T:","\\ukchsc01ds01\companyaccounts"
			wshnetwork.MapnetworkDrive "S:","\\ukchsc01ds01\companyadmin"
	 
	'ElseIf InStr(strGroups, chs_cleared_access) Then
	 
		Case "chs cleared access"
	 
			wshNetwork.MapNetworkDrive "R:","\\ukchsc01ds01\datasuite"
	 
	 
	'ElseIf InStr(strGroups, north) Then
	 
		Case "north"
	 
			WshNetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4650"
			wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hpdesignjet"
			wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hp2840"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Stores"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Directors"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4730-office"
			WshNetwork.SetDefaultPrinter "\\ukchsc01es01\hp4650"
	 
	'ElseIf InStr(strGroups, south) Then
	 
		Case "south"
	 
			WshNetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4650"
			wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hpdesignjet"
			wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hp2840"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Stores"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Directors"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4730-office"
			WshNetwork.SetDefaultPrinter "\\ukchsc01es01\hp4730-office"
	 
	'ElseIf InStr(strGroups, north east) Then
	 
		Case "north_east"
	 
			WshNetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4650"
			wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hpdesignjet"
			wshNetwork.AddwindowsPrinterConnection "\\ukchsc01es01\hp2840"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Stores"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp2600-Directors"
			wshnetwork.AddWindowsPrinterConnection "\\ukchsc01es01\hp4730-office"
			WshNetwork.SetDefaultPrinter "\\ukchsc01es01\hp2600-Directors"
	 
	End Select
End Sub

Open in new window

0
CHSCLMAuthor Commented:
Brilliant, Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.