Problem
You’re attempting to use the Set-MsolUser cmdlet to configure the immutableId attribute for a user in Azure Active Directory but receive the following error:
PS C:\> Set-MsolUser -UserPrincipalName jsmith@contoso.com -ImmutableId "zxGeOiOTdkivMtgkOsuvKA=="
Set-MsolUser : Uniqueness violation. Property: SourceAnchor.
At line:1 char:1
+ Set-MsolUser -UserPrincipalName jsmith@contoso.com -ImmutableId ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [Set-MsolUser], MicrosoftOnlineException
+ FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.UniquenessValidationException,Microsoft.Onlin
e.Administration.Automation.SetUser
PS C:\>
Reviewing the properties of the user account that you are trying to assign the immutableID value to confirms that it is null:
Get-MsolUser -UserPrincipalName jsmith@contoso.com | FL immutableId
Using Get-MsolUser to search for an account with the immutableID does not return any results:
Get-MsolUser | Where-Object {$_.ImmutableId -eq "zxGeOiOTdkivMtgkOsuvKA=="} | select UserPrincipalName
Solution
One of the most common reasons I’ve found for this error is if a deleted user object has the same immutableID assigned to it. A typical scenario would be:
- An effort was made to merge on-premise Active Directory accounts with Azure AD but Azure AD Connect created a new account with a random number following the name rather than merge the two accounts
- The administrator deletes the new account and attempts to assign the ObjectGUID (converted to base 64) of the on-premise Active Directory account to the Azure AD account
To confirm whether there is an account in the deleted users container, execute the following cmdlet:
Get-MsolUser -ReturnDeletedUsers
The following cmdlet can return the UPN along with the immutableID of the user accounts found in the deleted users container:
Get-MsolUser -ReturnDeletedUsers | FL UserPrincipalName,immutableID
Once the account with the conflicting immutableID is identified, the following cmdlet can be used to delete it:
Remove-MsolUser -UserPrincipalName jsmith@contoso.com -RemoveFromRecycleBin
With the account removed, you should now be able to assign the immutableID.