Getting all user profiles within SharePoint tenant using SharePoint Online CSOM API
- retrieve all the users in tenant (Get-MsolUser cmdlet)
- iterate users and utilize SharePoint User Profiles CSOM API to retrieve user profile
function Get-SPOContext([string]$Url,[string]$UserName,[string]$Password){$context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)$context.Credentials = Get-SPOCredentials -UserName $UserName -Password $Passwordreturn $context}function Get-SPOCredentials([string]$UserName,[string]$Password){$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Forcereturn New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)}function Print-UserProfileInfo([Microsoft.SharePoint.Client.UserProfiles.PeopleManager]$PeopleManager,[string]$AccountName){$ctx = $PeopleManager.Context$accountName = "i:0#.f|membership|" + $AccountName #claim format$userProfile = $PeopleManager.GetPropertiesFor($AccountName)$ctx.Load($userProfile)$ctx.ExecuteQuery()Write-Host $userProfile.PersonalUrl}