Guest User

Untitled

a guest
Mar 30th, 2018
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #Specify tenant admin and URL
  2. $User = "admin@tenant.onmicrosoft.com"
  3. #Configure Site URL and User
  4. $SiteURL = "https://tenant.sharepoint.com/sites/site"
  5. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
  6. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.UserProfiles.dll"
  7. $Password = Read-Host -Prompt "Please enter your password" -AsSecureString
  8. $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
  9. #Bind to Site Collection
  10. $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
  11. $Context.Credentials = $Creds
  12. #Identify users in the Site Collection
  13. $Users = $Context.Web.SiteUsers
  14. $Context.Load($Users)
  15. $Context.ExecuteQuery()
  16. #Create People Manager object to retrieve profile data
  17. $PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Context)
  18. Foreach ($User in $Users)
  19. {
  20. $UserProfile = $PeopleManager.GetPropertiesFor($User.LoginName)
  21. $Context.Load($UserProfile)
  22. $Context.ExecuteQuery()
  23. If ($UserProfile.Email -ne $null)
  24. {
  25. Write-Host "User:" $User.LoginName -ForegroundColor Green
  26. $UserProfile.UserProfileProperties
  27. Write-Host ""
  28. }
  29. }
Add Comment
Please, Sign In to add comment