Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param(
- $url = "https://blah.sharepoint.com/sites/dev",
- $username = "admin@blah.onmicrosoft.com",
- $password = "oopsalmostforgottoremovethis"
- )
- clear-host
- Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"
- Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"
- $securePassword = ConvertTo-SecureString $password -AsPlainText -Force
- $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url)
- #o365-auth
- $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
- $ctx.Credentials = $credentials
- $list = $ctx.Web.Lists.GetByTitle("Documents")
- $ctx.Load($list)
- #http://sharepoint.stackexchange.com/questions/126221/spo-retrieve-hasuniqueroleassignements-property-using-powershell
- Invoke-LoadMethod -Object $list -PropertyName "HasUniqueRoleAssignments"
- $ctx.ExecuteQuery()
- #break permissions inheritance
- if(!$list.HasUniqueRoleAssignments)
- {
- $list.BreakRoleInheritance(($copyRoleAssignments=$false), ($clearSubscopes=$true))
- $ctx.ExecuteQuery()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement