Advertisement
Guest User

Untitled

a guest
Sep 7th, 2016
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
  2. $username = "GlobalAdminUser@Test.onmicrosoft.com"
  3. $Adminurl = "https://Test-admin.sharepoint.com"
  4. $siteColUrl = "https://Test.sharepoint.com"
  5.  
  6.  
  7. try
  8. {
  9. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.dll"
  10. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.UserProfiles.dll"
  11. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
  12. Add-Type -Path "C:Program FilesCommon FilesMicrosoft SharedWeb Server Extensions16ISAPIMicrosoft.SharePoint.Client.UserProfiles.dll"
  13.  
  14.  
  15. #Bind to site collection
  16. $password = Read-Host -Prompt "Enter password" -AsSecureString
  17. $Context = New-Object Microsoft.SharePoint.Client.ClientContext($siteColUrl)
  18. #$ContextAdmin = New-Object Microsoft.SharePoint.Client.ClientContext($UserProfurl)
  19.  
  20. $Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username,$Password)
  21. $Context.Credentials = $Creds
  22. Write-Host "Successfully connected.." -ForegroundColor Green
  23.  
  24.  
  25. #Retrieve lists
  26. $web = $Context.Web
  27. $Users = $Context.Web.SiteUsers
  28. $items = $list.GetItems($query)
  29. $Context.Load($Users)
  30. $Context.Load($web)
  31.  
  32. $Context.ExecuteQuery()
  33. $CustomValue =10
  34. Write-Host $list.Title
  35. $PeopleManager = New-Object Microsoft.SharePoint.Client.UserProfiles.PeopleManager($Context)
  36. Write-Host $items.Count
  37.  
  38. Foreach ($User in $Users)
  39. {
  40. $UserNameValue = $User.LoginName
  41. $UserProfile = $PeopleManager.GetPropertiesFor($UserNameValue)
  42. $context.Load($UserProfile)
  43. $Context.ExecuteQuery()
  44. $PeopleManager.SetSingleValueProfileProperty($UserProfile.AccountName,"CustomValue", $CustomValue)
  45. $Context.ExecuteQuery()
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement