Consulting

Results 1 to 2 of 2

Thread: Listing the Computers list in a specific OU in a active directory

  1. #1

    Listing the Computers list in a specific OU in a active directory

    I have two OUs OU=Student and OU=Teachers and my root OU is LDAP://dc=test,dc=labs,dc=edu
    in the Student OU i have three computers named Std1,Std2,Std3 and three computers in Teachers OU named Tea1,Tea2,Tea3
    I am writing a VBA script in Excel in which i want to display my Computers in that OU in a excel spreadsheets.
    Computer Name Description OU
    Std1 Student Computers Student
    Std2 Student Computers Student
    ...................List goes on.......list of all computers in Student OU and Teachers OU
    This is my script but its not working can anyone help me?

    Added VBA Tags to code.
    ~Oorang

    [VBA]Sub ListDomains()

    Dim objNameSpace
    Dim Domain
    Dim ou
    Dim pcs
    Set objNameSpace = GetObject("LDAP://dc=test,dc=labs,dc=edu")
    For Each objDomain In objNameSpace
    ou = objDomain.Name
    objDomain.Filter = Array("Computer")

    For Each objComputer In objDomain
    pcs = objComputer.Name
    Dim i
    For i = 0 To pcs.Count - 1
    Cells(i, 1) = pcs
    Next
    Next
    Next

    End Sub[/VBA]

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    It's difficult to respond to this without being able to work in the same environment. What errors are you encountering? At which line?
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •