Script to dump users from AD to csv file

J

Jason

Hi,
I wanna dump the users from AD to a csv file. I´ve looked at Ldifde but I
haven´t gotten it to work as I want. I would like it to just dump the CN and
I´d like to run it through the entire AD witout having to list what OU:s to
include as I don´t have to update the script when / if I create a new OU.
I´d also would like it to exclude users if they are members of Domain Admins
or if they are members of Test. Is there a tool that I can use or is this
possible to VB-sript this?
Regards Jason
 
J

Jerold Schulman

Hi,
I wanna dump the users from AD to a csv file. I´ve looked at Ldifde but I
haven´t gotten it to work as I want. I would like it to just dump the CN and
I´d like to run it through the entire AD witout having to list what OU:s to
include as I don´t have to update the script when / if I create a new OU.
I´d also would like it to exclude users if they are members of Domain Admins
or if they are members of Test. Is there a tool that I can use or is this
possible to VB-sript this?
Regards Jason
Run this batch from Windows XP or Windows Server 2003:

@echo off
setlocal ENABLEDELAYEDEXPANSION
set qry=dsquery * forestroot -filter "(&(objectCategory=Person)(objectClass=User))" -attr distinguishedName -limit 0
for /f "Skip=1 Tokens=*" %%a in ('%qry%') do (
set dn=%%a#
set dn=!dn: =!
set dn=!dn: #=!
set dn="!dn:#=!"
for /f "Tokens=*" %%m in ('dsget user !dn! -memberOf') do (
For /f "Tokens=*" %%g in ('@echo %%m^|FIND /I "domain admins"') do set dn="NONE"
For /f "Tokens=*" %%g in ('@echo %%m^|FIND /I "test"') do set dn="NONE"
)
if !dn! NEQ "NONE" @echo !dn!
)
endlocal

Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
 
J

Jason

Thanx Jerold,
Thats more than I was hoping for. Tank you ever so much and for your great
site.
Have a good eastern.
Regards Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top