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.
This topic is 12 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
new_user
Posts: 157
Last visit: Tue May 06, 2014 5:46 pm

Check group membership

Post by new_user »

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
Last visit: Tue May 06, 2014 5:46 pm

Check group membership

Post by new_user »

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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Check group membership

Post by jvierra »

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?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Check group membership

Post by jvierra »

That is the actual statement.
Are you having issues because you do not understand VBscript? Post you exact queston. Maybe we can help.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Check group membership

Post by jvierra »

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.)(


This topic is 12 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked