Re: export account details from an OU

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



The script can be run on any computer authenticated to the domain. The
script creates the file Users.csv.

I would run it at a command prompt with the cscript host. For example, if
the script is saved in the file GetUsers.vbs (the file must have the *.vbs
extension), you can use the following command at a command prompt:

cscript GetUsers.vbs

This assumes you are in the folder where the file GetUsers.vbs is saved. If
not, you must specify the path and file name. The file Users.csv is created
in the same folder.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"Cyborg" <apollo13@xxxxxxxxxxxxxx> wrote in message
news:CB09A36A-435E-42AB-941A-74060EFC3554@xxxxxxxxxxxxxxxx
Hi, where do I run this?


"Salvador Manaois III" <SalvadorManaoisIII@xxxxxxxxxxxxxxxxxxxxxxxxx>
wrote in message
news:C86D70BB-ED1B-4F37-A418-6024F8563EE1@xxxxxxxxxxxxxxxx
Please try this (queries all users under the "sales" OU and sub-OUs):

On Error Resume Next

Const ADS_SCOPE_SUBTREE = 2
Const FOR_WRITING = 2
outFile = ".\Users.csv"

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objFSO = CreateObject("Scripting.FileSystemObject")

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

objCommand.CommandText = _
"SELECT Name FROM 'LDAP://ou=sales,dc=fabrikam,dc=com' WHERE
objectCategory='user'"
Set objRecordSet = objCommand.Execute

Set objOut = objFSO.CreateTextFile(outFile, FOR_WRITING)

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Echo objRecordSet.Fields("Name").Value
objOut.Writeline objRecordSet.Fields("Name").Value
objRecordSet.MoveNext
Loop

--
Salvador Manaois III
MCSE MCSA CEH MCITP | Enterprise/Server Admin
Bytes & Badz : http://badzmanaois.blogspot.com


"Cyborg" wrote:

Hi,

I need to export users from an OU to a CSV, this OU contains some more
OU's
that I also need the users exported from, how can I easiliy achieve
this?

Not sure if I can choose one OU and everything under this OU can be
exported?

Thanks





.



Relevant Pages

  • Re: & Now, a Script to List the Running Process Info - Re: Useful little Script to Show the
    ... Done that to the desktop folder, ... at a Command Prompt, with the Name of the Script File (after a Space, ... a Folder where the Command Prompt Opens (either the Root of the ...
    (uk.people.silversurfers)
  • Re: Adding Multiple Users to Multiple Groups.
    ... Const ADS_SCOPE_SUBTREE = 2 ... Finance Managers and Department Managers groups: ... Set objConnection = CreateObject ... Here is a revised script with a little error control so you can see any ...
    (microsoft.public.scripting.vbscript)
  • Re: Problem looping through OUs using LDAP
    ... figure out a way to have the script loop through the other 9 OUs. ... Const ADS_SCOPE_SUBTREE = 2 ... Dim fso, f ... Set objConnection = CreateObject ...
    (microsoft.public.scripting.vbscript)
  • Environment Problem
    ... I have patched together a script that creates a share, ... Const MAXIMUM_CONNECTIONS = 25 ... Wscript.Echo errReturn ... Set objConnection = CreateObject ...
    (microsoft.public.scripting.vbscript)
  • Pulling Names from multiple OUs
    ... I am trying to pull the Name from all of the User sub-OUs in AD. ... This is the script I am using now. ... Const ADS_SCOPE_SUBTREE = 2 ... Set objConnection = CreateObject ...
    (microsoft.public.windows.server.scripting)