Script to dump users from AD to csv file

Archived from groups: microsoft.public.win2000.active_directory (More info?)

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
2 answers Last reply
More about script dump users file
  1. Archived from groups: microsoft.public.win2000.active_directory (More info?)

    On Thu, 24 Mar 2005 11:46:48 +0100, "Jason" <jason_456@hotmail.com> wrote:

    >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
  2. Archived from groups: microsoft.public.win2000.active_directory (More info?)

    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
    "Jerold Schulman" <Jerry@jsiinc.com> wrote in message
    news:u7p541dtchlt2d7dud9uu509qhf9d5uebc@4ax.com...
    > On Thu, 24 Mar 2005 11:46:48 +0100, "Jason" <jason_456@hotmail.com> wrote:
    >
    >>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
Ask a new question

Read More

CSV Active Directory Windows