As the question basically says, is there a way to stop permissions inheritance on a list or a library via PowerShell?
Moreover there is a way to change user or group permissions on this list/library?
Thanks a lot!
Since SharePoint 2013/Online supports a sets of APIs, CSOM or REST APIs could be consumed in PowerShell for that purpose.
Prerequisites: SharePoint Online Client Components SDK
The example below shows how to assign unique permissions for a list using CSOM API in PowerShell:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
Function Get-ClientContext([string]$Url,[string]$UserName,[string]$Password)
{
$SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
$context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
return $context
}
Function List-BreakInheritance([Microsoft.SharePoint.Client.ClientContext]$Context,[string]$ListTitle)
{
$list = $Context.Web.Lists.GetByTitle($ListTitle)
$list.BreakRoleInheritance($true, $false)
$Context.ExecuteQuery()
}
$UserName = "[email protected]"
$Password = Read-Host -Prompt "Enter the password"
$Url = "https://contoso.sharepoint.com/"
$context = Get-ClientContext -Url $Url -UserName $UserName -Password $Password
List-BreakInheritance -Context $context -ListTitle "Tasks"
$context.Dispose()
As an alternative, you could also consider to utilize REST API.
Unfortunately this can't be done with PowerShell (yet). You have to use Office 365 API for this action.
Ref: Index of Windows PowerShell for SharePoint Online cmdlets