JSI Tip 7991. What OUs (Organizational Units) have I configured in my domain?

Using DSQUERY, an Active Directory command-line tool, I have scripted DomOU.bat to return the OUs that are configured in your domain.

NOTE: DomOU.bat does NOT return the Domain Controllers OU.

The syntax for using DomOU.bat is:


The output is displayed on the console, but you can redirect it to a file, using:


You can process the results in a batch, using a script similar to:

@echo off
for /f "Tokens=*" %%o in ('DomOU') do (
 call :Process %%o
exit /b 0
:: Process the OU here
@echo %1
DomOU.bat contains:
@echo off
for /f "Tokens=*" %%o in ('dsquery ou domainroot^|findstr /v /i /c:"OU=Domain Controllers,"') do (
 @echo %%o

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.