Hello,
Here is the script. You can use the script in Business Rules, Custom Commands and Scheduled Tasks. In the script, $newID specifies a template for a new Office 365 ID. You can use value references in the template (e.g. %firstname%). When the script runs, the value references will be replaced with property values of the user on which the rule, command or task is executed. For details, see https://www.adaxes.com/help/?ValueRefer ... ormat.html.
$newID = "%firstname:lower%.%lastname:lower%@example.com" # TODO: modify me
# Get the Office 365 object ID
try
{
$objectId = [GUID]$Context.TargetObject.Get("adm-O365ObjectId")
}
catch
{
$Context.LogMessage("The user doesn't have an Office 365 account", "Warning")
return
}
# Connect to Office 365
$Credential = $Context.GetOffice365Credential()
Connect-MsolService -Credential $Credential
# Check whether the Office 365 User ID differs from the new ID
$userO365 = Get-MsolUser -ObjectId $objectId
$o365Username = $userO365.UserPrincipalName
if ($o365Username -ieq $newID)
{
return # No changes needed
}
# Change the Office 365 User ID
Set-MsolUserPrincipalName -ObjectId $objectId -NewUserPrincipalName $newID
$Context.LogMessage("Office 365 User ID has been changed to: $newID", "Information")
For the script to work, you need to install Microsoft Azure Active Directory Module for Windows PowerShell on each computer where Adaxes service is running.
If you have a Business Rule which assigns Office 365 licenses to users, you can add the Run a program or PowerShell script action right after the Activate or modify Office 365 account action to update the ID automatically each time a user account is provisioned via Adaxes. The result should be like the following:
If you want to update Office 365 ID manually, you can use the script in a Custom Command configured for User object type and execute it on the users which you want to update. For information on how to create Custom Commands, have a look at the following tutorial: https://www.adaxes.com/tutorials_Active ... ommand.htm.
Also, you can use the script in a Scheduled Task to update Office 365 IDs on a periodic basis. The task should be configured for User object type. For information on how to create Scheduled Tasks, have a look at the following tutorial: https://www.adaxes.com/tutorials_Automa ... gement.htm.