![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 > .... > ======== 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 Specs![]() |
| | #3 (permalink) |
| | 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 > -- > 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 Specs![]() |
![]() |
| 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 | |||