Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

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
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

Avatar of Jeffrey Coachman
Jeffrey Coachman
Flag of United States of America image

Can you clearly state your question please?
Avatar of bsharath

ASKER

This script checks these 2 groups if the users are a member of 1 or both these groups

strGroupToCheck1 = "Full Time"
    strGroupToCheck2 = "Full Time Internet"

It does not get the info from the group2
This script checks these 2 groups if the users are a member of 1 or both these groups

strGroupToCheck1 = "Full Time"
    strGroupToCheck2 = "Full Time Internet"

It does not get the info from the group2
Chech your spelling in every instance of "Full Time Internet", and make sure it is spelled *exactly* the way it was originally assigned.

Also, obvoiusly, make sure that what you are searching for is actually in that group.
;-)

JeffCoachman
sharath,

can you post a sample sheet where this macro fails to work?

Thanks,
Ardhendu
Jeff the names are perfect...

Pari.

The file just has names in colum "L" which needs to query active directory groups and put in results as if the user is a member of the group or not.
Jeff the names are perfect...

Pari.

The file just has names in colum "L" which needs to query active directory groups and put in results as if the user is a member of the group or not.
Sharath,

Activedirectory is not one of my strong points. So I dont think I would be able to help you on this.

- Ardhendu


Ok Pari thanks....
Ok Pari thanks....
Hi Sharath,

This code works fine for me as it is.

Remember that the code will only re-check the groups if column BJ is empty for the row your querying.

Also, make sure you are viewing the entire data in that cell.  For example, when I run mine with GroupA and GroupB, the BJ cell then says
GroupA and GroupB

Maybe your column isn't wide enough to view the data?

What happens if you change
      strGroupToCheck1 = "Full Time"
      strGroupToCheck2 = "Full Time Internet"

to
      strGroupToCheck1 = "Full Time Internet"
      strGroupToCheck2 = "Full Time"

Do the results then swap around?

Regards,

Rob.
Hi Rob,

Yes the colum i removed all the data and ran and i get just 1 group and for the other group i get "NO"

Not even 1 user it retrieves if its in the other group
Hi Rob,

Yes the colum i removed all the data and ran and i get just 1 group and for the other group i get "NO"

Not even 1 user it retrieves if its in the other group
If you swap the group names around, do you get different results?
I did swap the names now. And now they work the other way. The names which got the groups show as "NO" and the other group works now
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks it works...
If a user is member of both groups. Will it show....
Thanks it works...
If a user is member of both groups. Will it show....
Yes, it should show
Group1Name and Group2Name

in the BJ column.

Rob.
Thank u Rob worked perfect
:-))