Script repository

Check if Organizational Unit has child objects

Updated on: Jan 18, 2026, Views: 4

Miscellaneous

The script checks whether the target Organizational Unit has child objects. The script should be executed in the If PowerShell script returns true condition in a business rule, custom command or scheduled task configured for the OrganizationalUnit object type. If the OU has no child objects, the script returns true.

# Search parameters
$searcher = $Context.TargetObject
$searcher.Criteria = New-AdmCriteria *
$searcher.PageSize = 500
$searcher.SearchScope = "ADS_SCOPE_ONELEVEL"
$searcher.ReferralChasing = "ADS_CHASE_REFERRALS_NEVER"
$searcher.SizeLimit = 1

try
{
    # Execute search
    $searchResult = $searcher.ExecuteSearch()
    $objects = $searchResult.FetchAll()
    
    $Context.ConditionIsMet = $objects.Count -eq 0
}
finally
{
    $searchResult.Dispose()
}

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    We use cookies to improve your experience.
    By your continued use of this site you accept such use.
    For more details please see our privacy policy and cookies policy.