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