"Clubsprint" <spamspamspamspam@xxxxxx> wrote in message
news:ggifit$po8$1@xxxxxx-01.bur.connect.com.au...
> I'm trying to create a file with a list of all users in a group and it's
> not working. I just end up with an empty file.
>
>
> Start script
> ==========================================
> On Error Resume Next
>
> Dim OrgUnit, GroupName, fso, f
>
> Const ForReading = 1, ForWriting = 2, ForAppending = 8
> Const OverwriteExisting = True
>
> 'delete existing copy of file
> 'Set objFSO = CreateObject("Scripting.FileSystemObject")
> 'objFSO.DeleteFile("C:\grouplist.txt")
>
> OrgUnit = "Users"
> GroupName = "Domain Users"
>
> Set objGroup = GetObject _
> '("LDAP://cn=Domain Users,cn=Users,dc=us,dc=com,dc=gov,dc=au")
>
> For Each objMember in objGroup.Members
>
> Set fso = CreateObject("Scripting.FileSystemObject")
> Set f = fso.OpenTextFile("C:\groups\" & GroupName & ".txt", ForAppending,
> True)
> f.WriteLine objMember.Name
> f.close
>
> Next
>
> MsgBox "File Created was C:\goups\" & GroupName & ".txt"
> 'Wscript.echo "Script Finished"
>
> 'start app
> 'RetVal = Process.Create (AppPath,WorkingDirectory,null,PID)
>
> ===============================================
> End Script
>
> "Domain Users" is a group under the "Users"
> I've also tried
> (LDAP://cn=Domain Users,ou=Users,dc=us,dc=com,dc=gov,dc=ca)
>
> What am I doing wrong?
> Thanks
>
> Most methods and attributes exposed by the LDAP provider, such as the
Members method of the group object, do not reveal membership in the
"primary" group. I would expect that all users in your domain have the group
"Domain Users" designated as their "primary". If so, the Members method of
the group object will return no member objects. The group will appear to be
empty.
An example VBScript program that enumerates all members of any group,
including membership due to group nesting and membership in the "primary"
group is linked here:
http://www.rlmueller.net/List%20Memb...0a%20Group.htm
If you don't want the membership due to nesting, comment out the recursive
call to Sub EnumGroup. The program retrieves the value of the
primaryGroupToken attribute of the designated group, then uses ADO to
retrieve all objects in AD that have the same value assigned to their
primaryGroupID attribute. This is probably the best way to determine all
objects (users, computers, groups) that have the group designated as their
"primary".
--
Richard Mueller
MVP Directory Services
Hilltop Lab -
http://www.rlmueller.net
--