Script Repository


Move user to a specific Organizational Unit

October 06, 2015
1300

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, for example, Adaxes custom property CustomAttributeText1.

To move users with the help of the script, you need to create a Business Rule triggered after creating or updating a user that will be triggered when the property is specified. For more details, see Run PowerShell Script after Creating a User. Sample Business Rule to run the script after updating a user:

Parameters:

  • $targetOuProperty - specifies the nane of the property that will be used to specify the DN of the OU.
Edit Remove
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()

Comments ( 0 )
No results found.
Leave a comment