Announcement

Collapse
No announcement yet.

Get list of users of some OU

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get list of users of some OU

    Hi, all!
    I'm wonderring how to get a list of users that are in some OU (including sub-OUs) using LDAP query. Actually I need it to create a Recipients policy in Exchange 2003 to create special addresses to users of some OU.
    Thanks
    Mykhaylo Khodorev

  • #2
    Re: Get list of users of some OU

    Code:
    On Error Resume Next
    
    Const ADS_SCOPE_SUBTREE = 2
    
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand =   CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection
    
    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 
    
    objCommand.CommandText = _
        "SELECT Name FROM 'LDAP://ou=MyUserOU,dc=domain,dc=co,dc=uk' WHERE objectCategory='user'"  
    Set objRecordSet = objCommand.Execute
    objRecordSet.MoveFirst
    
    Do Until objRecordSet.EOF
        Wscript.Echo objRecordSet.Fields("Name").Value
        objRecordSet.MoveNext
    Loop
    source : http://www.microsoft.com/technet/scr...s/default.mspx

    topper
    * Shamelessly mentioning "Don't forget to add reputation!"

    Comment


    • #3
      Re: Get list of users of some OU

      check this also:

      http://www.petri.com/list_all_users_..._in_domain.htm

      Comment


      • #4
        Re: Get list of users of some OU

        > Actually I need it to create a Recipients policy in Exchange 2003 to create special addresses to users of some OU.

        AFAIK, selection on OU cannot be done directly in a simple LDAP query. You need to be able to select an attribute (or combination of attributes) on the user to distinguish it. I'd love to be corrected though ...

        Comment


        • #5
          Re: Get list of users of some OU

          Can DSquery help with this task?
          You can scope your DSquery to a particular OU and output the results to a text file.

          @ cmd prompt:

          dsquery user ou=xxx,ou=yyy,dc=bobo,dc=com >c:\results.txt

          I'm not sure if this will automatically grab users in child OUs.

          DSquery info:
          http://www.microsoft.com/technet/pro...3d3046f01.mspx

          Comment


          • #6
            Re: Get list of users of some OU

            Originally posted by dp8888dp
            I'm not sure if this will automatically grab users in child OUs.
            dsquery by default is recursive - it uses the first argument as BASE DN for LDAP query and does SUBTREE search by default.
            You can control this behavior by explicitly specifying the scope with
            - scope {subtree | onelevel | base} switch
            Guy Teverovsky
            "Smith & Wesson - the original point and click interface"

            Comment


            • #7
              Re: Get list of users of some OU

              what does recursive mean in this context?

              Comment


              • #8
                Re: Get list of users of some OU

                Originally posted by dp8888dp
                what does recursive mean in this context?
                That it drills down the sub-OUs and sub-OUs of sub-OUs, etc...
                Guy Teverovsky
                "Smith & Wesson - the original point and click interface"

                Comment

                Working...
                X