Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Script Snippet to count members in a particular group

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,63303
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Script Snippet to count members in a particular group
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Script Snippet to count members in a particular group - 8/11/2008 3:53:11 AM   
  bilbrelb

 

Posts: 7
Score: 0
Joined: 8/1/2008
Status: offline
Hi, I've searched and didn't find just what I needed and hope someone can help.
I've written the following script to give me members of a group.
I need to also list the total number of members at the end of the listing.
That's the part I don't know where to begin to do.
Can someone help?
thanks
--Current Script--
On Error Resume Next
' Define Group Name
strGroupDN = "cn=groupname,ou=groups,ou=test,dc=rb,dc=testtree,dc=com"
'Setup File to Write To
Set fso = CreateObject("Scripting.FileSystemObject")
Set objTextFile = fso.OpenTextFile("C:\Scripts\Dev\RDPUsers.TSV",2, True)
set objGroup = GetObject("LDAP://" & strGroupDN)
objGroupName = objGroup.Get("name")
'Get Members
for each objMember in objGroup.Members
  ' Check to see if Account is disabled
  If objMember.AccountDisabled  = True Then
  accountDisabled = "Disabled"
  Else
  accountDisabled = "-------"
  End If
'Write output to Tab Delimited File
  objTextFile.WriteLine (objMember.Name & vbTab & objGroupName & vbTab & accountDisabled)
next
 
 
Post #: 1
 
 RE: Script Snippet to count members in a particular group - 8/11/2008 4:07:53 AM   
  dm_4ever


Posts: 2669
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Did you try

objGroup.Members.Count

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bilbrelb)
 
 
Post #: 2
 
 RE: Script Snippet to count members in a particular group - 8/11/2008 4:23:42 AM   
  bilbrelb

 

Posts: 7
Score: 0
Joined: 8/1/2008
Status: offline
I haven't heard of that. Searched the web for it and haven't found good usage of it yet.

I did find I could just put this in the For Each statement and it increments for each member.
Then I can just WriteLine Count to get the total.
If this the easiest way to do it?
Example:
for each objMember in objGroup.Members
  ' Check to see if Account is disabled
  If objMember.AccountDisabled  = True Then
  accountDisabled = "Disabled"
  Else
  accountDisabled = "-------"
  End If
  count = count + 1
'Write output to Tab Delimited File
  objTextFile.WriteLine (objMember.Name & vbTab & objGroupName & vbTab & accountDisabled)
next
objTextFile.WriteLine (Count)

(in reply to dm_4ever)
 
 
Post #: 3
 
 RE: Script Snippet to count members in a particular group - 8/11/2008 4:35:53 AM   
  dm_4ever


Posts: 2669
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
quote:

ORIGINAL: bilbrelb

I haven't heard of that. Searched the web for it and haven't found good usage of it yet.


....but did you try it to see if it shows you the group count?

Reference:  IADsMembers Interface ....you will see it is a valid property...so why bother creating your counter when the value is already available to you.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bilbrelb)
 
 
Post #: 4
 
 RE: Script Snippet to count members in a particular group - 8/11/2008 5:03:44 AM   
  bilbrelb

 

Posts: 7
Score: 0
Joined: 8/1/2008
Status: offline
Ah, I see what you mean. Sorry I'm new to vbscript.
Yes objGroup.Members.Count does pull the group membership count :)
Thanks much for the help.

I was also wanting to print out the OU location is a separate tab field and not the distinguished name.
Is there an attribute I can use to get jsut the user object OU and not the include the user name itself? This is for sorting purposes.

thanks again

(in reply to dm_4ever)
 
 
Post #: 5
 
 RE: Script Snippet to count members in a particular group - 8/11/2008 7:02:47 AM   
  dm_4ever


Posts: 2669
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
I don't believe there is a property with just the OU, but you can parse that information out from the distinguished name.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to bilbrelb)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Script Snippet to count members in a particular group Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts