• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1349
  • Last Modified:

Find all empty Ou's in the ADS.

Hi,

I want to get all the empty Ou's names to a file.

Regards
Sharath
0
bsharath
Asked:
bsharath
  • 2
1 Solution
 
RobOwner (Aidellio)Commented:
Use a recursive LDAP query

this should get you started: http://technet.microsoft.com/en-us/library/aa996205.aspx
0
 
Farhan KaziSystems EngineerCommented:
:: ===============
:: READ THIS FIRST
:: ===============
:: * Successful run will generate "EmptyOUs.txt" file on C: drive root.
:: * Copy and paste following script in notepad and save it with any name having .cmd extension.
::
:: *** SCRIPT START ***
@Echo Off
SETLOCAL EnableDelayedExpansion

IF EXIST C:\EmptyOUs.txt DEL /F /Q C:\EmptyOUs.txt
SET OUQry=DSQuery OU -Name * -Limit 0
FOR /F "delims=#" %%o IN ('%OUQry%') Do (
      Echo Processing: %%o
      DSQuery * %%o | Find "CN=" >NUL
      IF ERRORLEVEL 1 Echo Empty OU: %%o >>C:\EmptyOUs.txt
)
Echo.
Echo Search Complete! Check 'C:\EmptyOUs.txt' file.
Echo.
ENDLOCAL
:: *** SCRIPT END ***
0
 
bsharathAuthor Commented:
Dsquery has reached the default limit.?

I get this while it scans
0
 
Farhan KaziSystems EngineerCommented:
Try this:

:: ===============
:: READ THIS FIRST
:: ===============
:: * Successful run will generate "EmptyOUs.txt" file on C: drive root.
:: * Copy and paste following script in notepad and save it with any name having .bat extension.
::
:: *** SCRIPT START ***
@Echo Off
SETLOCAL EnableDelayedExpansion

IF EXIST C:\EmptyOUs.txt DEL /F /Q C:\EmptyOUs.txt
SET OUQry=DSQuery OU -Name * -Limit 0
FOR /F "delims=#" %%o IN ('%OUQry%') Do (
      Echo Processing: %%o
      DSQuery * %%o -Limit 0 | Find "CN=" >NUL
      IF ERRORLEVEL 1 Echo Empty OU: %%o >>C:\EmptyOUs.txt
)
Echo.
Echo Search Complete! Check 'C:\EmptyOUs.txt' file.
Echo.
ENDLOCAL
:: *** SCRIPT END ***
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now