Hi @CHAMBENOIT Louis,
In a typical SharePoint Online environment, The user profile synchronization process imports user profiles from On-Premises AD to Azure (through AD Sync Tool), and then from the Azure Active Directory (AAD), certain properties are mapped and synchronized with the SharePoint Online User Profiles.
Please install PnP Module and AzureAD Module first.
Here is the PowerShell to sync user email property value for all guest users:
AdminSiteURL = "https://crescent-admin.sharepoint.com"
$ADPropertyName = "proxyAddresses"
$SPOPropertyName = "WorkEmail"
#Get Credentials to connect to Azure AD and SharePoint Online Admin Center
$Cred = Get-Credential
Try {
#Connect to AzureAD
Connect-AzureAD -Credential $Cred | Out-Null
#Get All Users of the Domain from AzureAD
$AllUsers = Get-AzureADUser -All:$True -Filter "UserType eq 'Guest'"
Write-host "Total Number of User Profiles Found:"$AllUsers.Count
#Connect to PnP Online
Connect-PnPOnline -Url $AdminSiteURL -Credentials $Cred
#Iterate through All Users
$Counter = 1
ForEach($User in $AllUsers)
{
Write-host "`nUpdating User Profile Property for: $($User.UserPrincipalName)" -f Yellow
#Get the User Property value from Azure AD
$ADUserPropertyValue = $User | Select -ExpandProperty $ADPropertyName
#Check if the AD Property is not Null
If (!([string]::IsNullOrEmpty($ADUserPropertyValue)))
{
#Get existing User Profile Property from SharePoint
$UserAccount = "i:0#.f|membership|$($User.UserPrincipalName)"
$UserProfile = Get-PnPUserProfileProperty -Account $UserAccount
$UserProfileProperty = $UserProfile.UserProfileProperties[$SPOPropertyName]
#Check if the Existing SharePoint User Profile Property is Null
If (([string]::IsNullOrEmpty($UserProfileProperty)))
{
Set-PnPUserProfileProperty -Account $UserAccount -PropertyName $SPOPropertyName -Value $ADUserPropertyValue
Write-host "`tUpdated User Profile Property for: $($User.UserPrincipalName)" -f Green
}
Else
{
Write-host "`t Existing Value of the Property in SharePoint is Not Null! Skipping..." -f Yellow
}
}
else
{
Write-host "`t AD Value of the Property is Null! Skipping..." -f Yellow
}
$Counter++
Write-Progress -Activity "Updating User Profile Data..." -Status "Updating User Profile $Counter of $($AllUsers.Count)" -PercentComplete (($Counter / $AllUsers.Count) * 100)
}
}
Catch {
write-host -f Red "Error Updating User Profile Property!" $_.Exception.Message
}
Please note, this property update is only for SharePoint Online. It can’t be synced to Office 365 or Azure AD. User profile property created in the SharePoint Online admin center will not create or sync that property in Office 365!
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.