Announcement

Collapse
No announcement yet.

List computers in OU

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

  • List computers in OU

    can anyone help me with a vbscript that uses LDAP to list computers in a AD OU
    thanks


  • #2
    Re: List computers in OU

    Perhaps if you posted in the scripting forum you may get a better responce

    Reported for movement to the scripting forum

    Michael
    Michael Armstrong
    www.m80arm.co.uk
    MCITP: EA, MCTS, MCSE 2003, MCSA 2003: Messaging, CCA, VCP 3.5, 4, 5, VCAP5-DCD, VCAP5-DCA, ITIL, MCP, PGP Certified Technician

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

    Comment


    • #3
      Re: List computers in OU

      So moved..
      Tom Jones
      MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
      PhD, MSc, FIAP, MIITT
      IT Trainer / Consultant
      Ossian Ltd
      Scotland

      ** Remember to give credit where credit is due and leave reputation points where appropriate **

      Comment


      • #4
        Re: List computers in OU

        Quit simple, but it isnt vbs.

        DSQUERY USER OU=Name of the ou,DC=name of the domain,DC=Suffix > c:\UsersinOU.TXT
        [Powershell]
        Start-DayDream
        Set-Location Malibu Beach
        Get-Drink
        Lay-Back
        Start-Sleep
        ....
        Wake-Up!
        Resume-Service
        Write-Warning
        [/Powershell]

        BLOG: Therealshrimp.blogspot.com

        Comment


        • #5
          Re: List computers in OU

          If you plan on doing a lot of scripts like this, there is a book about how to do a lot of things with active directory. It tells you how to do it using DS commands and VB. here is a link to the book:

          http://www.oreilly.com/catalog/activedckbk2/

          here is what you would be looking at:
          Code:
          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.CommandText = _
          "Select Name, Location from 'LDAP://OU=OUNAME,DN=domain,DN=com' " _
          & "Where objectCategory='computer'"
          objCommand.Properties("Page Size") = 1000
          objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
          Set objRecordSet = objCommand.Execute
          objRecordSet.MoveFirst
          Do Until objRecordSet.EOF
          Wscript.Echo "Computer Name: " & objRecordSet.Fields("Name").Value
          Wscript.Echo "Location: " & objRecordSet.Fields("Location").Value
          objRecordSet.MoveNext
          Loop
          As an FYI i havent tested this script and it is a modified script... the original script found all computers in domain. all you do is add the OU to the LDAP query. make sure you edit the "LDAP://OU=OUNAME,DN=domain,DN=com" portion to match your domain
          Technology is only as good as those who use it

          My tech blog - wiredtek.wordpress.com

          Comment


          • #6
            Re: List computers in OU

            Killerbe does have the simplest way... but the below is for computers
            Note that you'll need to enclose the DN with quotes if there's spaces in the OU names. In the example below I'm looking in an OU name Test Search in the jeremy.test domain

            Code:
            DSQUERY COMPUTERS "OU=Test Search,DC=jeremy,DC=test" > c:\ComputersInOU.TXT
            You also may want just the computer name instead of the full Distinguished Name (DN)
            Code:
            DSQUERY COMPUTERS "OU=Test Search,DC=jeremy,DC=test" -o rdn > c:\ComputersInOU.TXT
            Regards,
            Jeremy

            Network Consultant/Engineer
            Baltimore - Washington area and beyond
            www.gma-cpa.com

            Comment

            Working...
            X