This articles talks about steps to update data from exchange online to SharePoint Online user profiles. Below script will do below steps part of sync,
1. Connect to Exchange Online by opening session.
2. Connect to SharePoint Online Admin Centre
3. Connect to SharePoint Online site collection. As SharePoint Online allows update to User Profiles through site collection.
4. Read through each profile from exchange online and will try to find the user available in SharePoint Online user profiles.
5. If user profile available, it will update.
Below script sample retrieving mobile number from exchange online and update to SharePoint Online user profiles,
Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll'
Import-Module 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll'
#Admin User Principal Name
$admin = <admin email address>
#Get Password as secure String
$password = convertto-securestring <Password of above admin account> -asplaintext -force
#Authenticate
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $admin, $password
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $credentials -Authentication Basic -AllowRedirection
Import-PSSession $Session
$Users = Get-User -ResultSize unlimited -RecipientType UserMailbox
$Users.Count
#Mysite URL
$site = 'https://<SharePoint Online Domain>-admin.sharepoint.com/' # This needs to be the "admin" site.
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($admin,$password)
#Get the Client Context and Bind the Site Collection
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)
$context.Credentials = $Creds
#Create an Object [People Manager] to retrieve profile information
$people = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($context)
$siteurl = 'https://<SharePoint Online Domain>.sharepoint.com/'
$sitecontext = New-Object Microsoft.SharePoint.Client.ClientContext($siteurl)
$sitecontext.Credentials = $Creds
ForEach($User in $Users)
{
$userprofile = $people.GetPropertiesFor("i:0#.f|membership|" + $User.UserPrincipalName)
$context.Load($userprofile)
$context.ExecuteQuery()
$mobileno = Get-User $User.UserPrincipalName | fl MobilePhone | Out-String
if($mobileno.ToString().Trim().Length -gt 13)
{
$people.SetSingleValueProfileProperty("i:0#.f|membership|" + $User.UserPrincipalName,"CellPhone", $mobileno.ToString().Trim().Substring(14))
$context.ExecuteQuery()
}
}
Powershell to sync exchange online to SharePoint Profiles
ReplyDeleteGood post to learn about the powershell to sync exchange online...
Keep sharing the great content... We will suggest your post to the developers...
Well, read our blog Top 8 Important Skills to Learn To Become a SharePoint Developer
Microsoft SharePoint Developer