Script repository

Copy property values between on-premises and Entra accounts

Updated on: Jan 18, 2026, Views: 2508

User accounts, Copying and moving

The scripts copy values of the specified properties from the target on-premises AD account to the corresponding Microsoft Entra account and vice versa. To execute the script, create a business rule, custom command or scheduled task configured for the User object type.

In the scripts, the $propertiesToCopy variable specifies schema names of the properties whose values will be copied.

Both scripts must be executed on the on-premises AD account.

Script 1: Copy property values from the target on-premises AD account to the Microsoft Entra one

$propertiesToCopy = @("adm-CustomAttributeText1", "adm-CustomAttributeText2") # TODO: modify me

# Bind to the Microsoft Entra account.
try
{
    $entraId = $Context.TargetObject.Get("adm-AzureId")
}
catch
{
    $Context.LogMessage("User %fullname% has no Microsoft Entra identifier", "Information")
    return
}

try
{
    $entraAccount = $Context.BindToObject("Adaxes://<GUID=$entraId>")
}
catch
{
    $Context.LogMessage("User %fullname% has no Microsoft Entra account", "Information")
    return
}

# Update properties of the Microsoft Entra account.
foreach ($propertyToCopy in $propertiesToCopy)
{
    try
    {
        $propertyValue = $Context.TargetObject.Get($propertyToCopy)
    }
    catch
    {
        continue
    }
    
    # Save the changes
    $entraAccount.Put($propertyToCopy, $propertyValue)
}
$entraAccount.SetInfo()

Script 2: Copy property values from the the Microsoft Entra account to the target on-premises AD account

$propertiesToCopy = @("adm-CustomAttributeText1", "adm-CustomAttributeText2") # TODO: modify me

# Bind to the Microsoft Entra account.
try
{
    $entraId = $Context.TargetObject.Get("adm-AzureId")
}
catch
{
    $Context.LogMessage("User %fullname% has no Microsoft Entra identifier", "Information")
    return
}

try
{
    $entraAccount = $Context.BindToObject("Adaxes://<GUID=$entraId>")
}
catch
{
    $Context.LogMessage("User %fullname% has no Microsoft Entra account", "Information")
    return
}

# Update properties of the AD account.
foreach ($propertyToCopy in $propertiesToCopy)
{
    try
    {
        $propertyValue = $entraAccount.Get($propertyToCopy)
    }
    catch
    {
        continue
    }
    
    # Save the changes
    $Context.TargetObject.Put($propertyToCopy, $propertyValue)
}
$Context.TargetObject.SetInfo()

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.