Gavin5511
asked on
How to output the full OU path for a number of AD accounts.
Hi there,
I want to output the full OU path for serveral AD accounts. I'm running a DSQuery that searches particular OUs, and then a DSGet to output certain fields to txt files (-display, -samid,-title etc). The query is attached.
That part works fine. But I can't work out how to output the OU path for those same accounts. Can anyone help?
I want to output the full OU path for serveral AD accounts. I'm running a DSQuery that searches particular OUs, and then a DSGet to output certain fields to txt files (-display, -samid,-title etc). The query is attached.
That part works fine. But I can't work out how to output the OU path for those same accounts. Can anyone help?
@ECHO off
REM ***************************************************************************
REM The following OUs are INCLUDED:
REM - Generic Accounts
REM - Service Accounts
REM - Telephony Accounts
REM - Training Accounts
REM - Vendor Dial-In Accounts
REM The following OUs are EXCLUDED:
REM - Dead Users
REM - To Delete
REM
REM
REM ***************************************************************************
REM Script Initialization Section
title Generic User Accounts
color 0c
set logfile=error.log
set output1=%temp%\genericusers1.csv
set output2=%temp%\genericusers2.csv
set output3=%temp%\genericusers3.csv
set outputtmp=%temp%\genericusers.tmp
set limit=4000
REM Main Processing Section
if exist %temp%\*.csv erase %temp%\*.csv 2>>%logfile% >nul
if exist %temp%\*.tmp erase %temp%\*.tmp 2>>%logfile% >nul
cls
echo.
echo Processing. Please wait...
echo.
dsquery user ou=uk,dc=corp,dc=ad -limit %limit% | findstr /c:"OU=Generic Accounts" /c:"OU=Service Accounts" /c:"OU=Telephony Accounts"
/c:"OU=Training Accounts" /c:"OU=Vendor Dial-In Accounts" | dsget user -display -samid -title -distinguishedName>> %output1%
dsquery user ou=uk,dc=corp,dc=ad -limit %limit% | findstr /c:"OU=Generic Accounts" /c:"OU=Service Accounts" /c:"OU=Telephony Accounts"
/c:"OU=Training Accounts" /c:"OU=Vendor Dial-In Accounts" | dsget user -mgr >> %output2%
cls
echo.
echo Done.
echo.
pause
cls
echo.
echo Formatting. Please wait...
echo.
for /f "skip=1 delims==, tokens=1-2" %%a in (%output2%) do (
echo %%b >> %outputtmp%
for %%c in (%outputtmp%) do if %%~zc equ 0 (
echo. >> %output3%
)
echo %%b >> %output3%
)
cls
echo.
echo Done. Hit any key to display the output files.
echo.
pause
start notepad %output1%
start notepad %output3%
title %comspec%
color
cls
REM Subroutine and Procedure Section
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.