2016-07-13 1 views

답변

0

우리는 M icrosoft 그래프 아래의 요청을 통해 모든 사용자를 검색 할 수 있습니다 :

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

당신은 표시 이름, 모바일 폰, 메일 속성을 통해 사용자 이름, 모바일 및 전자 메일 얻을 수 있습니다. 그리고 프로필 사진을 얻기 위해, 우리는 각 사용자에 대해 다음과 같은 요청을 보낼 필요가 :

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

마이크로 소프트 그래프를 호출 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 
관련 문제