Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Find all users and the OU's and the Computers and there Ou

Hi,

I want to see which are users are there in which OU and the same way the computers.
Ex:
Username : OUname
Regards
Sharath
Avatar of SPOued
SPOued

Do you mean:
I want to see which users are in which OU? and Which computers are in which OU too?
You can use "Find" in ADUC to search for user or computer objects within OU...
Avatar of bsharath

ASKER

I want this to a file. I have all users and computers scattered in different Ou's.
You want list of all user ID's and Computer names along with their OU's in following format

FileOne:
UserName : OUname

FileTwo:
ComputerName : OUname

Rite?
Avatar of oBdA
This script (no changes necessary) will create two csv files, named like the script, but with -user and -computer, respectively, at the end, and the extension .csv.
Can't test it at the moment, but it should work:

@echo off
setlocal
set LogFile=%~dpnx0-User.csv
call :process user
set LogFile=%~dpnx0-Computer.csv
call :process computer
goto :eof
:process
for /f "delims=" %%a in (dsquery %~1 -limit 0) do set ObjectDN=%%~a
for /f "tokens=2 delims=,=" %%a in ("%ObjectDN%") do set ObjectName=%%a
>>"%LogFile%" echo "%ObjectName%";"%ObjectDN%"
goto :eof
Farhankazi
Yes you are correct.
Obda
this does not give any data in the files created.
ASKER CERTIFIED SOLUTION
Avatar of Farhan Kazi
Farhan Kazi
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry, this works now (script extension in the log name is now dropped, too):

@echo off
setlocal
set LogFile=%~dpn0-User.csv
call :process user
set LogFile=%~dpn0-Computer.csv
call :process computer
goto :eof
:process
for /f "delims=" %%a in ('dsquery %~1 -limit 0') do (
  for /f "tokens=2 delims=,=" %%m in (%%~a) do >>"%LogFile%" echo "%%m";%%a
)
goto :eof
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial