2016-07-13 4 views
-1

Как получить все пользовательские профили в семействе сайтов с помощью JSOM/CSOM или REST API?Как я могу получить все профили пользователей в семействе сайтов? (SharePoint Online O365)

Я не нахожу ничего, что полностью работает, мне нужны следующие свойства:

  • Имя пользователя
  • Mobile
  • Электронная почта
  • фото

Заранее спасибо

ответ

0

Мы можем использовать M icrosoft Graph для получения всех пользователей с помощью следующей просьбы:

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

Вы можете получить имя пользователя, мобильные и электронной почты через DisplayName, MobilePhone, почты собственности. А чтобы получить картину профиля, мы должны отправить запрос, как показано ниже для каждого пользователя:

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

И вызвать API Microsoft Graph REST, необходимо зарегистрировать приложение и предоставить подходящее разрешение для приложения.

Сфера для 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 

И так как мы должны получить профиль различных пользователей, мы должны использовать приложение только лексемы (Daemon сервис приложение).

Обратитесь к here для вызова Microsoft Graph в приложении

0

службы или демона Если вам нужно просто экспортировать всех пользователей в файл, использовать PowerShell. вам нужно изменить 2 вещи в коде ниже: расположения клиентских библиотек и веб-сайта urtl.

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 

 Смежные вопросы

  • Нет связанных вопросов^_^