This PowerShell script moves a user to an Organizational Unit whose distinguished name (DN) is specified by a certain property of the user's account. To execute the script, create a business rule triggered after creating or updating a user that will be triggered when the property is changed.
Parameters:
- $targetOuProperty - Specifies the name of the property that will be used to specify the DN of the OU.
PowerShell
$targetOuProperty = "adm-CustomAttributeText1" # TODO: Modify me
# Get the target OU DN
$targetOuDN = $Context.TargetObject.Get($targetOuProperty)
# Bind to the target OU
try
{
$targetOU = $Context.BindToObjectByDN($targetOuDN)
}
catch
{
$Context.LogMessage("The target location '$targetOuDN' does not exist.", "Error")
return
}
# Move the user
try
{
$targetOU.MoveHere($Context.TargetObject.AdsPath, $NULL)
}
catch
{
$Context.LogMessage($_.Exception.Message, "Error")
return
}
# Clear the property
$Context.TargetObject.Put($targetOuProperty, $NULL)
$Context.TargetObject.SetInfo()