3 replies
by jlewter Accepted solution
by djskeud Accepted solution
Hi all,
I made exactly what you want below ... Find group membership related to a user, even group include in other groups.
Scenario :
"Member1" is member of "Group1"
"Member2" is member of "Group2"
"Group2" is member of "Group1"
Results :
1. When Member1 is starting, the array "AllFoundGroups()" contains "Group1"
2. When Member1 is starting, the array "AllFoundGroups()" contains "Group2" AND "Group1"
By using this script, you'll be able to conserve only one Auto-logon script in your Group Policies, and then make some filters to mount or not map drives on function of groups memberships.
'###########
' START SCRIPT
'###########
On Error Resume Next
' DEFINE VARIALBES '
'****************
Dim objWshNetwork, ADSysInfo, CurrentUser, Groups, UNCpath, Username, CurrentGroup, AllFoundGroups(), NbGroupFound, GroupAlreadyExists
' MAIN '
'************
Set objWshNetwork = CreateObject("WScript.Network")
Username= objWshNetwork.UserName
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
Groups = UCase(Join(CurrentUser.MemberOf))
CurrentGroup = ""
NbGroupFound = 0
GroupAlreadyExists = 0
'----------
' Creation of the array AllFoundGroups()
' Contains all groups the User is in
'----------
For Each GroupsMemberOf In CurrentUser.MemberOf '
FunctionListedGroupMembership(GroupsMemberOf)
Next
msgbox(CurrentUser & " is in those groups : " & Join(AllFoundGroups," || "))
For Each CurrentGroup In AllFoundGroups
' Exemple of the way it can be used to mount map drives
Set objNetwork = CreateObject("WScript.Network")
If StrComp(CurrentGroup, UCase("Group Share AdminShared"))=0 Then
objNetwork.RemoveNetworkDrive "J:"
objNetwork.MapNetworkDrive "J:", "\\FileServer\ShareFolder$"
End If
Next
' FUNCTIONS '
'*****************
Function FunctionListedGroupMembership(GroupsMemberOf)
strGroupOnly = Mid(GroupsMemberOf,4,InStr(GroupsMemberOf,",")-4)
'Test if the current group is already contain in the Array
If Not InStr(Join(AllFoundGroups), strGroupOnly ) Then
' Making of the array
ReDim Preserve AllFoundGroups(NbGroupFound)
AllFoundGroups(NbGroupFound) = Ucase(strGroupOnly)
NbGroupFound = NbGroupFound + 1
Set objGroup = GetObject("LDAP://" & GroupsMemberOf)
objGroup.GetInfo
' Get all members in current group.
arrMemberOf = objGroup.GetEx("memberOf")
if Not IsEmpty(arrMemberOf) Then ' Test if the current group is itself member of ather groups
For Each strMember in arrMemberOf
strMemberOnly = Mid(strMember,4,InStr(strMember,",")-4)
FunctionListedGroupMembership(strMember)
Next
End If
End If
Set arrMemberOf = Nothing
Set strMember = Nothing
Set objGroup = Nothing
End Function
'###########
' END SCRIPT
'###########
Hope it can be helpfull for someone :)
Do not hesitate if you have any comment or remark.
Best,
Thomas
by lnkemp Accepted solution
I am trying to change this from an if statement to a case statement but I am getting errors when I do. Can you check my code and tell me what I am doing wrong? Thanks for the original by the way, it works perfectly!
'###########
' START SCRIPT
'###########
On Error Resume Next
' DEFINE VARIALBES '
'****************
Dim objWshNetwork, ADSysInfo, CurrentUser, Groups, UNCpath, Username, CurrentGroup, AllFoundGroups(), NbGroupFound, GroupAlreadyExists
' MAIN '
'************
Set objWshNetwork = CreateObject("WScript.Network")
Username= objWshNetwork.UserName
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
Groups = UCase(Join(CurrentUser.MemberOf))
CurrentGroup = ""
NbGroupFound = 0
GroupAlreadyExists = 0
'----------
' Creation of the array AllFoundGroups()
' Contains all groups the User is in
'----------
For Each GroupsMemberOf In CurrentUser.MemberOf '
FunctionListedGroupMembership(GroupsMemberOf)
Next
msgbox(CurrentUser & " is in those groups : " & Join(AllFoundGroups," || "))
For Each CurrentGroup In AllFoundGroups
' Exemple of the way it can be used to mount map drives
Set objNetwork = CreateObject("WScript.Network")
Select Case CurrentGroup
Case CurrentGroup = "BMS Students"
objNetwork.RemoveNetworkDrive "M:"
objNetwork.MapNetworkDrive "M:", "\\Luke\apps"
Case CurrentGruop = "BMS Faculty/Staff"
objNetwork.RemoveNetworkDrive "Z:"
objNetwork.MapNetworkDrive "Z:", "\\Luke\apps"
'Next
' FUNCTIONS '
'*****************
Function FunctionListedGroupMembership(GroupsMemberOf)
strGroupOnly = Mid(GroupsMemberOf,4,InStr(GroupsMemberOf,",")-4)
'Test if the current group is already contain in the Array
If Not InStr(Join(AllFoundGroups), strGroupOnly ) Then
' Making of the array
ReDim Preserve AllFoundGroups(NbGroupFound)
AllFoundGroups(NbGroupFound) = Ucase(strGroupOnly)
NbGroupFound = NbGroupFound + 1
Set objGroup = GetObject("LDAP://" & GroupsMemberOf)
objGroup.GetInfo
' Get all members in current group.
arrMemberOf = objGroup.GetEx("memberOf")
if Not IsEmpty(arrMemberOf) Then ' Test if the current group is itself member of ather groups
For Each strMember in arrMemberOf
strMemberOnly = Mid(strMember,4,InStr(strMember,",")-4)
FunctionListedGroupMembership(strMember)
Next
End If
End If
Set arrMemberOf = Nothing
Set strMember = Nothing
Set objGroup = Nothing
End Function
'###########
' END SCRIPT
'###########
I only have two groups listed right now but there will be about 8 or 10 total each with at least one server location or more. I feel like it must be a syntax error, and I'm not a vbscript expert ;-)
This discussion is closed to new replies.
Trending Networks posts
Sort by Trending