|
From: Udo on 24 Jun 2008 10:46 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
From: Richard Mueller [MVP] on 24 Jun 2008 12:56 "Udo" <Udo(a)discussions.microsoft.com> wrote in message news:5F377B13-866A-4965-B365-50DF01B96072(a)microsoft.com... > 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 --
From: Richard Mueller [MVP] on 24 Jun 2008 17:45 "Richard Mueller [MVP]" <rlmueller-nospam(a)ameritech.nospam.net> wrote in message news:%23ux0Ath1IHA.3968(a)TK2MSFTNGP04.phx.gbl... > > "Udo" <Udo(a)discussions.microsoft.com> wrote in message > news:5F377B13-866A-4965-B365-50DF01B96072(a)microsoft.com... >> 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 --
|
Pages: 1 Prev: 800A0007 Out of memory retrieving AD object Next: vbscript error 70 - permission denied |