Advertisement
Guest User

Untitled

a guest
Jul 20th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. param(
  2. $url = "https://blah.sharepoint.com/sites/dev",
  3. $username = "admin@blah.onmicrosoft.com",
  4. $password = "oopsalmostforgottoremovethis"
  5. )
  6.  
  7. clear-host
  8.  
  9. Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"
  10. Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
  11.  
  12. $securePassword = ConvertTo-SecureString $password -AsPlainText -Force
  13.  
  14. $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url)
  15. #o365-auth
  16. $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
  17. $ctx.Credentials = $credentials
  18.  
  19. $list = $ctx.Web.Lists.GetByTitle("Documents")
  20. $ctx.Load($list)
  21. #http://sharepoint.stackexchange.com/questions/126221/spo-retrieve-hasuniqueroleassignements-property-using-powershell
  22. Invoke-LoadMethod -Object $list -PropertyName "HasUniqueRoleAssignments"
  23. $ctx.ExecuteQuery()
  24.  
  25. #break permissions inheritance
  26. if(!$list.HasUniqueRoleAssignments)
  27. {
  28. $list.BreakRoleInheritance(($copyRoleAssignments=$false), ($clearSubscopes=$true))
  29. $ctx.ExecuteQuery()
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement