Windows Vista Forums

Group membership script not working-help
  1. #1


    Clubsprint Guest

    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

  2. #2


    Richard Mueller [MVP] Guest

    Re: Group membership script not working-help


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



      My System SpecsSystem Spec

  3. #3


    Clubsprint Guest

    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

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


      My System SpecsSystem Spec

Group membership script not working-help problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
check group membership Eero J PowerShell 3 17 Feb 2009
Script to query user information based upon group membership Brian VB Script 2 10 Nov 2008
Get group membership David Arro PowerShell 2 31 Aug 2008
Get Group Membership for a User LE2 Strat PowerShell 4 31 Jan 2008
Group Membership Don D Vista mail 0 15 Sep 2007