Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Specify tenant admin and URL
- $User = "admin@tenant.onmicrosoft.com"
- #Configure Site URL and User
- $SiteURL = "https://tenant.sharepoint.com/sites/site"
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.UserProfiles.dll"
- $Password = Read-Host -Prompt "Please enter your password" -AsSecureString
- $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
- #Bind to Site Collection
- $Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
- $Context.Credentials = $Creds
- #Identify users in the Site Collection
- $Users = $Context.Web.SiteUsers
- $Context.Load($Users)
- $Context.ExecuteQuery()
- #Create People Manager object to retrieve profile data
- $PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Context)
- Foreach ($User in $Users)
- {
- $UserProfile = $PeopleManager.GetPropertiesFor($User.LoginName)
- $Context.Load($UserProfile)
- $Context.ExecuteQuery()
- If ($UserProfile.Email -ne $null)
- {
- Write-Host "User:" $User.LoginName -ForegroundColor Green
- $UserProfile.UserProfileProperties
- Write-Host ""
- }
- }
Add Comment
Please, Sign In to add comment