Script repository
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.