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.

Script repository

Copy property values from on-premises account to Entra one

January 02, 2025 Views: 45

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

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

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

# Bind to the 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 Entra account
foreach ($propertyToCopy in $propertiesToCopy)
{
    try
    {
        $propertyValue = $Context.TargetObject.Get($propertyToCopy)
    }
    catch
    {
        continue
    }
    
    # Save the changes
    $entraAccount.Put($propertyToCopy, $propertyValue)
    $entraAccount.SetInfo()
}
Comments 0
Leave a comment
Loading...

Got questions?

Support Questions & Answers