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 - Group membership script not working-help

Reply
 
Old 11-25-2008   #1 (permalink)
Clubsprint


 
 

Group membership script not working-help

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






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


 
 

Re: Group membership script not working-help


"Clubsprint" <spamspamspamspam@xxxxxx> wrote in message
news:ggifit$po8$1@xxxxxx-01.bur.connect.com.au...
Quote:

> 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
--


My System SpecsSystem Spec
Old 11-26-2008   #3 (permalink)
Clubsprint


 
 

Re: Group membership script not working-help

Thanks Richard. You saved the day again.

"Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in
message news:usww1n3TJHA.1172@xxxxxx
Quote:

>
> "Clubsprint" <spamspamspamspam@xxxxxx> wrote in message
> news:ggifit$po8$1@xxxxxx-01.bur.connect.com.au...
Quote:

>> 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
> --
>
>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
check group membership PowerShell
Script to query user information based upon group membership VB Script
Get group membership PowerShell
Get Group Membership for a User PowerShell
Group Membership 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