更新时间:2021-09-14 07:42:20
正如您提到的,没有使用 SharePoint Online CSOM API 在 SharePoint 租户中获取所有用户配置文件的直接方法.但您可以考虑以下方法:
As you mentioned, there is no straightforward ways of getting all user profiles within SharePoint tenant using SharePoint Online CSOM API. But you could consider the following approach:
Get-MsolUser
cmdlet)Get-MsolUser
cmdlet)示例
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.UserProfiles.dll"
Function Get-SPOContext([string]$Url,[string]$UserName,[string]$Password)
{
$context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$context.Credentials = Get-SPOCredentials -UserName $UserName -Password $Password
return $context
}
Function Get-SPOCredentials([string]$UserName,[string]$Password)
{
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
return 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
}
$tenantUrl = "https://contoso.sharepoint.com/"
$userName = "jdoe@contoso.onmicrosoft.com"
$password = "password"
$secPassword = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($userName, $secPassword)
Connect-MsolService -Credential $cred
$allUsers = Get-MsolUser
$Context = Get-SPOContext -Url $tenantUrl -UserName $userName -Password $password
$peopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Context)
$allUsers | % { Print-UserProfileInfo -PeopleManager $peopleManager -AccountName $_.UserPrincipalName }
$Context.Dispose()