txgeekgirl
Registered User.
- Local time
- Today, 06:39
- Joined
- Jul 31, 2008
- Messages
- 187
I have some script that adds people into groups based on their supervisors choices. We do, however, have supervisors that choose over and over... they forget their requsts....
Based on this code and adding a check where I have marked - does anyone know a surefire piece of code to check group affiliation?
Based on this code and adding a check where I have marked - does anyone know a surefire piece of code to check group affiliation?
Code:
Sub Add_ExistingAD2Groups(IdentRecordFromRequest)
Dim gname, sname, sGroupName, FullName As String
Dim oUser As IADsUser
gname = DLookup("NewStaff_F_Name", "NewStaffRequests", "ID = " & IdentRecordFromRequest)
sname = DLookup("NewStaff_L_Name", "NewStaffRequests", "ID = " & IdentRecordFromRequest)
sGroupName = DLookup("DefaultPrinter", "NewStaffRequests", "ID = " & IdentRecordFromRequest)
If Len(DLookup("SharedFolders", "NewStaffRequests", "ID = " & IdentRecordFromRequest)) > 0 Then
sGroupName = sGroupName & "," & DLookup("SharedFolders", "NewStaffRequests", "ID = " & IdentRecordFromRequest)
End If
If Len(DLookup("Databases", "NewStaffRequests", "ID = " & IdentRecordFromRequest)) > 0 Then
sGroupName = sGroupName & "," & DLookup("Databases", "NewStaffRequests", "ID = " & IdentRecordFromRequest)
End If
If Len(DLookup("EmailGroups", "NewStaffRequests", "ID = " & IdentRecordFromRequest)) > 0 Then
sGroupName = sGroupName & "," & DLookup("EmailGroups", "NewStaffRequests", "ID = " & IdentRecordFromRequest)
End If
'clean groups
sGroupName = Replace(sGroupName, "NoGroup,", "")
sGroupName = Replace(sGroupName, ",,", ",")
FullName = gname & " " & sname
'Open modifying connection to Active Directory
Set RootDSE = GetObject("[URL="ldap://RootDSE/"]LDAP://RootDSE[/URL]")
DomainContainer = RootDSE.Get("defaultNamingContext")
Set oOU = GetObject("[URL]ldap://CN=Users;DC=domain,DC=com[/URL]")
' Update User Record
Set oUser = oOU.Create("user", "cn=" & FullName)
' Add the user to a group
Dim index As Integer
Dim sEachGroup As String
Dim IsMember As Boolean
Do While Len(sGroupName) > 0
'End of list - can't have a string going from 1 to 0
If InStr(sGroupName, ",") <> 0 Then
index = InStr(sGroupName, ",")
Else
index = 50
End If
sEachGroup = Mid(sGroupName, 1, index - 1)
'MsgBox (sEachGroup)
StrobjGroup1 = "[URL="ldap://cn/"]LDAP://cn[/URL]=" & sEachGroup & ",cn=Users,DC=pbmhmr,DC=com"
Set objGroup1 = GetObject(StrobjGroup1)
:confused:'******NEED A CHECK HERE
objGroup1.Add (oUser.ADsPath)
UpdateDBLog sEachGroup, FullName, ID
sGroupName = Mid(sGroupName, index + 1)
Loop
' Cleanup
Set oUser = Nothing
MsgBox ("This employee has been added to groups in Active Directory.")
End Sub