"rademr1" <rademr1@xxxxxx> wrote in message
news:45CAECA0-64B8-415B-8C94-428C68F60150@xxxxxx
>I am looking for a little help on how to take the script below and put the
> results in a CSV file. I got this script from the Microsoft Scriptcenter
> and
> it displays all the members of an Active Directory Group.
>
> On Error Resume Next
>
> Set objGroup = GetObject _
> ("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")
> objGroup.GetInfo
>
> arrMemberOf = objGroup.GetEx("member")
>
> WScript.Echo "Members:"
> For Each strMember in arrMemberOf
> WScript.echo strMember
> Next
>
> First, since your script uses Wscript.Echo, you can also redirect the output
to a text file. You would run the script at a command prompt using cscript.
For example:
cscript //nologo Example.vbs > report.txt
Next, the GetEx method in your script will raise an error if the group has
no members. That's why it has "On Error Resume Next". I would trap the error
and echo this condition (no members) with code similar to:
==========
Set objGroup = GetObject _
("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")
On Error Resume Next
arrMemberOf = objGroup.GetEx("member")
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "No members"
Else
On Error GoTo 0
WScript.Echo "Members:"
For Each strMember in arrMemberOf
WScript.echo strMember
Next
End If
===========
Finally, it might make sense to use the Members method of the group object,
which never raises an error. This method returns a collection of member
objects (not just DN's), so you have access to all attributes of the
members:
==========
Set objGroup = GetObject _
("LDAP://cn=Scientists,ou=R&D,dc=NA,dc=fabrikam,dc=com")
For Each objMember In objGroup.Members
Wscript.Echo objMember.distinguishedName
Next
==========
If instead you wanted to document the "pre-Windows 2000 logon" name, you
could use objMember.sAMAccountName.
--
Richard Mueller
MVP Directory Services
Hilltop Lab -
http://www.rlmueller.net
--