?
Solved

Need to view users in an OU within Active Directory.

Posted on 2007-11-29
4
Medium Priority
?
184 Views
Last Modified: 2010-04-30
Anyone know a quick and easy way to view all the users in a OU.  I tried using CSVDE but the txt file came out pretty garbled?

I tried finding step by step instructions, but nothing came up.

Thanks,
0
Comment
Question by:yoyoma788
[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
  • 2
4 Comments
 
LVL 17

Expert Comment

by:JohnGerhardt
ID: 20375122
Sorry if this sounds obvious but why dont you use the Active Directory AD mmc snap in?
-Jaggie
0
 

Author Comment

by:yoyoma788
ID: 20375965
No I'm trying to give a list to our secretary.  So hopefully I could export it into a spreadsheet or something like that.

0
 
LVL 17

Accepted Solution

by:
JohnGerhardt earned 1000 total points
ID: 20380387
Hi yoyoma788,

Below is a quick VB script to do what you want. It just echos out all of the users in the OU that you have selected in the varibales section at the top. If you want some help writing out to a file then give me a shout.

Just create a text file and name it ConnectToTheAD.vbs => copy and paste the script in there and edit the varibles. Run it from the command prompt with cscript.

Tell me how it goes....
-Jaggie
'Constants
Const ADS_SCOPE_SUBTREE = 2
Const adUseClient = 3
 
 
'Variables Here
OU = "YOUR OU HERE" 'Enter your OU here
strDNC = "DC=YOUR DOMAIN,DC=HERE" ' Enter your AD root here
FindWhat = "user" ' Change to either user or computer to find either users or computer in the AD
'End Variables
 
	Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
 
    Set objCommand.ActiveConnection = objConnection
	
	Set objStdOut = WScript.StdOut
 
'=================================================Main Routine Start ===============================================
 
Call QueryTheAD 'Get List from the AD
 
'=================================================Main Routine End ===============================================
 
Sub QueryTheAD
  objCommand.CommandText = "Select Name, Location from 'LDAP://" &  strDNC & "' " & "Where objectClass='"& FindWhat & "'"
  objCommand.Properties("Page Size") = 1000
  objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
  objCommand.Properties("Sort on") = "Name"
  Set objRecordSet = objCommand.Execute
 
    Do Until objRecordSet.EOF
    	MachineCount = MachineCount + 1 
    	strComputer = objRecordSet.Fields("Name").Value
    		WScript.Echo strComputer
    	objRecordSet.MoveNext
    Loop	  	
End Sub

Open in new window

0
 

Author Comment

by:yoyoma788
ID: 20381256
I'll give it a shot.  Thanks for the post.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

801 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