Check group membership

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
new_user
Posts: 157
Joined: Wed May 30, 2007 7:01 am

Check group membership

Post by new_user » Wed Feb 08, 2012 10:03 am

I will post back questions. All I am trying to do is echo the group name if it has a user object as a member. These groups should only have groups as members, not a user(s), so if it contains classs user, echo the group name, thats all. I can get all the groups and all their memebers but thats to much info. Just need to know if a group has memebers that are user objects and if so, ech that groups name, thats it.

User avatar
new_user
Posts: 157
Joined: Wed May 30, 2007 7:01 am

Check group membership

Post by new_user » Wed Feb 08, 2012 12:13 pm

Hi. I addede that in the loop but may have been the incorrect spot as it echo's the group once for each time it finds a user (if 5 users in group x it echos the group name 5 times. I know it needs to review the group memebers, while it does that is the class is user echo the name but not sure where that goes. Do Until adoRecordset.EOF strName = adoRecordset.Fields("name").Value strDN = adoRecordset.Fields("distinguishedName").value Wscript.Echo strName & ";" & strDN Set group = GetObject("LDAP://" & strDN ) For Each member in group.Members set obj = GetObject(member.aDSPath) if obj.class = "user" Then WScript.Echo group.name End If 'WScript.Echo obj.class Next adoRecordset.MoveNextLoop

User avatar
jvierra
Posts: 13275
Joined: Tue May 22, 2007 9:57 am
Contact:

Check group membership

Post by jvierra » Wed Feb 08, 2012 1:13 pm

Try keeping your code readable. You will find you learn much from this excersize.

Code: Select all

	
Gotuser = False ' make a flag variable
	
For Each member in group.Members
        set obj = GetObject(member.aDSPath)
        if obj.lass = "user" Then
                  ' WScript.Echo strName
	
                  GotUser=True ' we have a user so set the flag
        End If
	
        'WScript.Echo obj.class
    Next
	
    ' check to see f we found a user and report!
	
    if GotUser Then Wscript.echo group.Name
	
 
	

So simple. Jids do this all of the time and drive me f****** nuts showinf off how smart they are.

Us so called 'adults' need to catch up to the 'script kiddies' but it requires fearlessness and a desirte to attemp to do something new.

Are you that daring?

User avatar
jvierra
Posts: 13275
Joined: Tue May 22, 2007 9:57 am
Contact:

Check group membership

Post by jvierra » Wed Feb 08, 2012 3:49 pm

That is the actual statement.
Are you having issues because you do not understand VBscript? Post you exact queston. Maybe we can help.

User avatar
jvierra
Posts: 13275
Joined: Tue May 22, 2007 9:57 am
Contact:

Check group membership

Post by jvierra » Wed Feb 08, 2012 4:13 pm

Seems to work fine, I have not compared to groups to validate the data but I do understand vbscript just not all of it maybe, can't know everything but trying.

So that is the best base from which to ask a question.

Knowing what we don't know is, somtimes, better than knowing. - 'Yee old filosifer..' (Remeb4er Filo? He had an orangutan friend.)(



Locked