1

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!

2 Answers 2

1

Since SharePoint 2013/Online supports a sets of APIs, CSOM or REST APIs could be consumed in PowerShell for that purpose.

How to stop permissions inheritance for a List in SharePoint Online

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.

0

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

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.