Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - VBS reading all groups from OU and there members

Reply
 
Old 06-24-2008   #1 (permalink)
Udo


 
 

VBS reading all groups from OU and there members

Hello,

Iam a vbs beginner and I want to write all distribution groups and there
members from one ou in a textfile. I want to write each group and there
associated members in one row, separated with semikolon. The next group with
there members in an second row, and so on.
But in my script, the groups and each member are written one above the
other. Reason: I don`t know how to write from an array to a textfile in one
row!

the codefile:
....
set oDomain = GetObject ("LDAP://" & strDomain)
oDomain.Filter = Array("Group")
FOR EACH strGroup in oDomain
File.Writeline strGroup.SamAccountName
arrMemberof = strGroup.GetEx("member")
FOR EACH strMember in arrMemberof
File.WriteLine strMember
Next
Next
.....

Thanks!



--
Gruß Udo

My System SpecsSystem Spec
Old 06-24-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: VBS reading all groups from OU and there members


"Udo" <Udo@xxxxxx> wrote in message
news:5F377B13-866A-4965-B365-50DF01B96072@xxxxxx
Quote:

> Hello,
>
> Iam a vbs beginner and I want to write all distribution groups and there
> members from one ou in a textfile. I want to write each group and there
> associated members in one row, separated with semikolon. The next group
> with
> there members in an second row, and so on.
> But in my script, the groups and each member are written one above the
> other. Reason: I don`t know how to write from an array to a textfile in
> one
> row!
>
> the codefile:
> ...
> set oDomain = GetObject ("LDAP://" & strDomain)
> oDomain.Filter = Array("Group")
> FOR EACH strGroup in oDomain
> File.Writeline strGroup.SamAccountName
> arrMemberof = strGroup.GetEx("member")
> FOR EACH strMember in arrMemberof
> File.WriteLine strMember
> Next
> Next
> ....
>
Use a variable to concatenate values into one line. For example:
========
FOR Each objGroup in oDomain
strLine = objGroup.sAMAccountName
arrMembers = arrGroup.Get("member")
If IsEmpty(arrMembers) Then
' No members.
ElseIf (TypeName(arrMembers) = "String") Then
' One member in group.
strLine = strLine & ";" & arrMembers
Else
' At least two members in group.
For Each strMember In arrMembers
strLine = strLine & ";" & strMember
Next
End If
' Output the line.
File.WriteLine strLine
Next
======
I also modified the code to prevent error is the group has no members or one
member. For more on handling the "member" attribute of groups (or the
"memberOf" attribute of users) so that all situations are handled see this
link:

http://www.rlmueller.net/MemberOf.htm

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 06-24-2008   #3 (permalink)
Richard Mueller [MVP]


 
 

Re: VBS reading all groups from OU and there members


"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:%23ux0Ath1IHA.3968@xxxxxx
Quote:

>
> "Udo" <Udo@xxxxxx> wrote in message
> news:5F377B13-866A-4965-B365-50DF01B96072@xxxxxx
Quote:

>> Hello,
>>
>> Iam a vbs beginner and I want to write all distribution groups and there
>> members from one ou in a textfile. I want to write each group and there
>> associated members in one row, separated with semikolon. The next group
>> with
>> there members in an second row, and so on.
>> But in my script, the groups and each member are written one above the
>> other. Reason: I don`t know how to write from an array to a textfile in
>> one
>> row!
>>
>> the codefile:
>> ...
>> set oDomain = GetObject ("LDAP://" & strDomain)
>> oDomain.Filter = Array("Group")
>> FOR EACH strGroup in oDomain
>> File.Writeline strGroup.SamAccountName
>> arrMemberof = strGroup.GetEx("member")
>> FOR EACH strMember in arrMemberof
>> File.WriteLine strMember
>> Next
>> Next
>> ....
>>
>
> Use a variable to concatenate values into one line. For example:
> ========
> FOR Each objGroup in oDomain
> strLine = objGroup.sAMAccountName
> arrMembers = arrGroup.Get("member")
> If IsEmpty(arrMembers) Then
> ' No members.
> ElseIf (TypeName(arrMembers) = "String") Then
> ' One member in group.
> strLine = strLine & ";" & arrMembers
> Else
> ' At least two members in group.
> For Each strMember In arrMembers
> strLine = strLine & ";" & strMember
> Next
> End If
> ' Output the line.
> File.WriteLine strLine
> Next
> ======
> I also modified the code to prevent error is the group has no members or
> one member. For more on handling the "member" attribute of groups (or the
> "memberOf" attribute of users) so that all situations are handled see this
> link:
>
> http://www.rlmueller.net/MemberOf.htm
>
> --
> Richard Mueller
> MVP Directory Services
> Hilltop Lab - http://www.rlmueller.net
> --
>
If you only want to document distribution groups (skip security groups), you
can check the groupType attribute of the group objects. Also, if you only
want the groups in an OU, bind to the OU rather than the domain. For
example:
===========
Const ADS_GROUP_TYPE_SECURITY_ENABLED = &H80000000

Set objOU = GetObject("LDAP://ou=Sales,ou=West,dc=MyDomain,dc=com")
objOU.Filter = Array("group")
For Each objGroup in objOU
' Check if distribution group (not security enabled).
If (objGroup.groupType And ADS_GROUP_TYPE_SECURITY_ENABLED) = 0 Then
strLine = objGroup.sAMAccountName
arrMembers = arrGroup.Get("member")
If IsEmpty(arrMembers) Then
' No members.
ElseIf (TypeName(arrMembers) = "String") Then
' One member in group.
strLine = strLine & ";" & arrMembers
Else
' At least two members in group.
For Each strMember In arrMembers
strLine = strLine & ";" & strMember
Next
End If
' Output the line.
File.WriteLine strLine
End If
Next

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Finding members of RDP groups of a list of computers VB Script
retrive all AD groups and its members VB Script
How to create a list with all distrubtion groups and it's members PowerShell
Sending bulk bcc e-mails to members groups Vista mail
Contact Groups: Cannot Select Members Vista mail


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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