2016-07-13 4 views
-1

JSOM/CSOMまたはREST APIを使用してサイトコレクション内のすべてのユーザープロファイルを取得するにはどうすればよいですか。サイトコレクション内のすべてのユーザープロファイルを取得するにはどうすればよいですか? (SharePoint Online O365)

私は次のプロパティを必要とする、完全に機能し、何も見つからなかっ:

  • ユーザー名
  • モバイル
  • Eメール
  • プロフィール画像事前

感謝

答えて

0

M以下の要求を経由してすべてのユーザーを取得するためのicrosoftグラフ:

GET:https://graph.microsoft.com/v1.0/users 

あなたはユーザ名を取得することができ、のDisplayNamemobilePhoneメールプロパティを介して移動し、Eメール。また、プロフィール画像を取得するために、我々はユーザーごとに以下のようなリクエストを送信する必要があります。

https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/photo/$value 

とMicrosoftグラフREST APIを呼び出すために、私たちは、アプリを登録して、アプリに適した権限を付与する必要があります。

List Userのための適用範囲:

User.ReadBasic.All; User.Read.All; User.ReadWrite.All; Directory.Read.All; Directory.ReadWrite.All; Directory.AccessAsUser.All 

get photoのための適用範囲:

User.Read; User.ReadBasic.All; User.Read.All; User.ReadWrite.All; User.Read 

そして、我々は、異なるユーザのプロファイルを取得する必要があるため、我々はアプリ専用トークン(デーモンサービスを使用する必要がありますアプリ)。あなただけのPowerShellを使用して、ファイルにすべてのユーザーをエクスポートする必要がある場合は

は、サービスまたはデーモンアプリ

0

でMicrosoftグラフを呼び出すためのhereを参照してください。 以下のコードでは、クライアントライブラリの場所とサイトコレクションのurlの2つを変更する必要があります。

Add-Type -Path "c:\DLLS\Microsoft.SharePoint.Client.dll" 
    Add-Type -Path "c:\DLLS\Microsoft.SharePoint.Client.Runtime.dll" 
    Add-Type -Path "c:\DLLS\Microsoft.SharePoint.Client.UserProfiles.dll" 

    #Mysite URL 
    $site = 'https://NAME.sharepoint.com/' 

    #Get the Client Context and Bind the Site Collection 
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($site) 

    #Authenticate 
    $newCredentials = Get-Credential 
    $UserName = $newCredentials.UserName 
    $SecurePassword = $newCredentials.Password 
    $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword) 
    $context.Credentials = $credentials 

    #Fetch the users in Site Collection 
    $users = $context.Web.SiteUsers 
    $context.Load($users) 
    $context.ExecuteQuery() 


    #Create an Object [People Manager] to retrieve profile information 
    $people = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($context) 
    $collection = @() 

    Write-Host "Found" $users.Count " users. Exporting..." 

    for($I = 1; $I -lt $users.Count; $I++){ 
     try 
     { 
      $percCompl = [Math]::Floor(($I/$users.Count) * 100) 
      Write-Progress -Activity Updating -Status 'Progress->' -CurrentOperation "$percCompl% complete" -PercentComplete $percCompl; 
      $user = $users[$I] 
      $userprofile = $people.GetPropertiesFor($user.LoginName) 
      $context.Load($userprofile) 
      $context.ExecuteQuery() 

      $profileData = "" | Select "FirstName", "LastName", "UserName", "WorkEmail", "WorkPhone", "Department", "JobTitle", "Location", "SiteUrl" 
      if($userprofile -ne $null -and $userprofile.Email -ne $null) 
      { 
       $upp = $userprofile.UserProfileProperties 
       $profileData.FirstName = $upp.FirstName 
       $profileData.LastName = $upp.LastName 
       $profileData.UserName = $upp.UserName 
       $profileData.WorkEmail = $upp.WorkEmail 
       $profileData.WorkPhone = $upp.WorkPhone 
       $profileData.Department = $upp.'SPS-Department' 
       $profileData.JobTitle = $upp.'SPS-JobTitle' 
       $profileData.Location = $upp.'SPS-Location' 
       $profileData.SiteUrl = $site 
       $collection += $profileData 
      } 
      else{ 
       $profileData.FirstName = $user.UserId 
       $profileData.LastName = $upp.Title 
       $profileData.WorkEmail = $user.Email 
       $profileData.SiteUrl = $site 
       $collection += $profileData 
      }    
     } 
     catch 
     { 
      Write-Host "UserError: " $user.LoginName ". Error detail:" $($_) 
     } 
    } 

    $collection | Export-Csv C:\SPO-Users.csv -NoTypeInformation -Encoding UTF8 
    Write-Host "Done!" -ForegroundColor Green 
関連する問題