Script repository

Check whether object is moved to specific OU

Updated on: Jan 18, 2026, Views: 2098

Miscellaneous

The script returns $true if an object is moved to the specified Organizational Unit or container. To execute the script, use the If PowerShell script returns true condition in a business rule triggering Before moving an object.

In the script, the $containerDN variable specifies the distinguished name (DN) that should match the target container DN for the condition to be met. For information on how to get the DN, see Get the DN of a directory object.

$containerDN = "OU=Disabled Accounts,DC=company,DC=com" # TODO: modify me

# Get target container DN.
$targetContainer = $Context.Action.TargetContainer
if ($targetContainer)
{
    $targetContainerDN = $targetContainer.Get("distinguishedName")
}
else
{
    $targetContainerDN = $Context.Action.TargetContainerDnTemplate
}

$Context.ConditionIsMet = $targetContainerDN -eq $containerDN

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.