Link to home
Start Free TrialLog in
Avatar of Indie101

asked on

Script to find any empty OU and nested OU in Active Directory


Looking for a best way to do this

I was checking out script below

Get-ADObject -filter * -SearchBase $ou | Where {$_.distinguishedname -ne $ou.distinguishedname} keep getting error below

 Get-ADObject : Cannot validate argument on parameter 'SearchBase'. The argument is null. Provide a valid value for the argument, and then try running the command again.
At line:1 char:36
+ Get-ADObject -filter * -SearchBase $ou | Where {$_.distinguishedname  ...
+                                    ~~~
    + CategoryInfo          : InvalidData: (:) [Get-ADObject], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADObject

Avatar of Emmanuel Adebayo
Emmanuel Adebayo
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Indie101


Thanks Emmanuel, just piped it to csv and it looks well, it gives some great detail , managed details. does all that come from searchscope being used with Get-ADOrganizationalUnit? Looks exactly what I need