bsharath
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
I want to see which are users are there in which OU and the same way the computers.
Ex:
Username : OUname
Regards
Sharath
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?
FileOne:
UserName : OUname
FileTwo:
ComputerName : OUname
Rite?
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.c sv
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
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.c
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
ASKER
Farhankazi
Yes you are correct.
Obda
this does not give any data in the files created.
Yes you are correct.
Obda
this does not give any data in the files created.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.cs v
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
@echo off
setlocal
set LogFile=%~dpn0-User.csv
call :process user
set LogFile=%~dpn0-Computer.cs
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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...