Question : Check that check groups for members and places the group name that its available. One group data is not pulled.

Hi,

Check that check groups for members and places the group name that its available. One group data is not pulled.
Full time works but not the other group. even if the user is a member i get "NO"

If the user is a member of both groups for few i ger and for few NO
This script check the colum names with the Active directory group.

Regards
sharath
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
Sub Check_If_Member_Of_Internet_Groups()
      strGroupToCheck1 = "Full Time"
    strGroupToCheck2 = "Full Time Internet"
    
    Set objNetwork = CreateObject("WScript.Network")
    For intRow = 2 To Cells(65536, "L").End(xlUp).Row
        strNTLogin = Trim(Cells(intRow, "L").Value)
        If strNTLogin <> "" Then
            If Trim(Cells(intRow, "BJ").Value) = "" Then
                On Error Resume Next
                Set objWinntUser = GetObject("WinNT://" & objNetwork.UserDomain & "/" & strNTLogin & ",user")
                If Err.Number = 0 Then
                    On Error GoTo 0
                  If (IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck1) = True) And (IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck2) = True) Then
 
                        Cells(intRow, "BJ").Value = strGroupToCheck1 & " and " & strGroupToCheck2
                    ElseIf (IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck1) = True) Or (IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck1) = True) Then
                        If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck1) = True Then
                            Cells(intRow, "BJ").Value = strGroupToCheck1
                        ElseIf IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck2) = True Then
                            Cells(intRow, "BJ").Value = strGroupToCheck2
                        End If
                    ElseIf (IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck1) = False) And (IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck1) = False) Then
                        Cells(intRow, "BJ").Value = "No"
                    End If
                Else
                    Err.Clear
                    On Error GoTo 0
                End If
                Set objWinntUser = Nothing
            End If
        End If
    Next
    
End Sub
 
Function IsMemberOfGroup(strUserDomain, objuser, strGroup) 'the user is a member of a specified group
    IsMemberOfGroup = False
    Dim objGroup
    On Error Resume Next
    Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
    If Err.Number Then
        IsMemberOfGroup = "Error"
    Else
        IsMemberOfGroup = objGroup.IsMember(objuser.adsPath)
        'MsgBox objUser.ADsPath
    End If
End Function
Open in New Window Select All

Answer : Check that check groups for members and places the group name that its available. One group data is not pulled.

Oh!  Oops!  Copy and paste error by the look of it....a couple of lines were checking only Group1 twice, instead of Group1 and Group2....
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
Sub Check_If_Member_Of_Internet_Groups()
    strGroupToCheck1 = "Full Time"
    strGroupToCheck2 = "Full Time Internet"
    
    Set objNetwork = CreateObject("WScript.Network")
    For intRow = 2 To Cells(65536, "L").End(xlUp).Row
        strNTLogin = Trim(Cells(intRow, "L").Value)
        If strNTLogin <> "" Then
            If Trim(Cells(intRow, "BJ").Value) = "" Then
                On Error Resume Next
                Set objWinntUser = GetObject("WinNT://" & objNetwork.UserDomain & "/" & strNTLogin & ",user")
                If Err.Number = 0 Then
                    On Error GoTo 0
                    If (IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck1) = True) And (IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck2) = True) Then
                        Cells(intRow, "BJ").Value = strGroupToCheck1 & " and " & strGroupToCheck2
                    ElseIf (IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck1) = True) Or (IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck2) = True) Then
                        If IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck1) = True Then
                            Cells(intRow, "BJ").Value = strGroupToCheck1
                        ElseIf IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck2) = True Then
                            Cells(intRow, "BJ").Value = strGroupToCheck2
                        End If
                    ElseIf (IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck1) = False) And (IsMemberOfGroup(objNetwork.UserDomain, objWinntUser, strGroupToCheck2) = False) Then
                        Cells(intRow, "BJ").Value = "No"
                    End If
                Else
                    Err.Clear
                    On Error GoTo 0
                End If
                Set objWinntUser = Nothing
            End If
        End If
    Next
    
End Sub
 
Function IsMemberOfGroup(strUserDomain, objuser, strGroup) 'the user is a member of a specified group
    IsMemberOfGroup = False
    Dim objGroup
    On Error Resume Next
    Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
    If Err.Number Then
        IsMemberOfGroup = "Error"
    Else
        IsMemberOfGroup = objGroup.IsMember(objuser.adsPath)
        'MsgBox objUser.ADsPath
    End If
End Function
Open in New Window Select All
Random Solutions  
 
programming4us programming4us