Solved

How to query a specific OU or container in AD^

Posted on 2008-06-17
2
1,023 Views
Last Modified: 2012-05-05
Hi Experts,

I need to list all computer in AD but our computer are not in the defaut OU or container. How can I query at the right place?
Computers are under \\Domain\Internal\Computers
' Connect to domain and retrieve distinguish name.
	Set objRoot = GetObject("LDAP://RootDSE") 
	Set objDomain = GetObject("LDAP://" & objRoot.Get("DefaultNamingContext")) 
	' Build Query to list only computer names from AD.
	strQuery = "Select Name From '" & objDomain.ADsPath & "' where objectClass='computer'"

Open in new window

0
Comment
Question by:EricPelletier
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Expert Comment

by:sk_raja_raja
ID: 21802532
run "csvde" againt the domain controller...you will be able to get all the computer objects in .csv
0
 
LVL 38

Accepted Solution

by:
Shift-3 earned 500 total points
ID: 21802826
You can use the script from this article:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/dec04/hey1207.mspx

Just comment out lines 21, 22, and 24 to return all computers in the domain.

To list all computers under an OU and its sub-OUs use this script:
http://www.microsoft.com/technet/scriptcenter/resources/qanda/oct05/hey1013.mspx

Change "user" to "computer" in line 15.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…

689 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question