SOLVED

How Do I break inheritance on a List or web using PnP Powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-78059%22%20slang%3D%22en-US%22%3EHow%20Do%20I%20break%20inheritance%20on%20a%20List%20or%20web%20using%20PnP%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78059%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHow%20do%20I%20break%20inheritance%20on%20a%20list%20or%20web%20using%20PnP%20PowerShell%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMust%20be%20with%20PowerShell%20running%20on%20a%20client%26nbsp%3BNOT%20on%20the%20SharePoint%20server.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENigel%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78104%22%20slang%3D%22en-US%22%3ERe%3A%20How%20Do%20I%20break%20inheritance%20on%20a%20List%20or%20web%20using%20PnP%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78104%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F2387%22%20target%3D%22_blank%22%3E%40Pieter%20Veenstra%3C%2FA%3E%26nbsp%3B%20marked%20as%20solution%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-78103%22%20slang%3D%22en-US%22%3ERe%3A%20How%20Do%20I%20break%20inheritance%20on%20a%20List%20or%20web%20using%20PnP%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-78103%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1992%22%20target%3D%22_blank%22%3E%40Nigel%20Price%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI've%20got%20a%20list%20called%20Testlist%20in%20the%20root%20of%20my%20site%20collection%20that%20I%20connected%20to%20with%20ConnectPnPOnline.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20following%206%20lines%20now%20do%20what%20you%20need%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24web%20%3D%20Get-PnPWeb%20-Identity%20%22%2F%22%26nbsp%3B%0A%24spoList%3D%20Get-PnPList%20%22Testlist%22%20-Web%20%24web%26nbsp%3B%0A%24spoList.BreakRoleInheritance(%24true%2C%20%24true)%0A%24spoList.Update()%0A%0A%24spoList.Context.Load(%24spoList)%0A%24spoList.Context.ExecuteQuery()%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1151811%22%20slang%3D%22en-US%22%3ERe%3A%20How%20Do%20I%20break%20inheritance%20on%20a%20List%20or%20web%20using%20PnP%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1151811%22%20slang%3D%22en-US%22%3EThis%20works%20for%20web%20as%20well%3CBR%20%2F%3E%24web.BreakRoleInheritance(%24true%2C%20%24false)%3CBR%20%2F%3E%24web.Update()%3CBR%20%2F%3E%24web.Context.Load(%24web)%3CBR%20%2F%3E%24web.Context.ExecuteQuery()%3C%2FLINGO-BODY%3E
Highlighted
Contributor

Hi

 

How do I break inheritance on a list or web using PnP PowerShell ?

 

Must be with PowerShell running on a client NOT on the SharePoint server.

 

Thanks

 

Nigel

3 Replies
Highlighted
Best Response confirmed by Nigel Price (Contributor)
Solution

Hi @Nigel Price

 

I've got a list called Testlist in the root of my site collection that I connected to with ConnectPnPOnline.

 

The following 6 lines now do what you need:

 

$web = Get-PnPWeb -Identity "/" 
$spoList= Get-PnPList "Testlist" -Web $web 
$spoList.BreakRoleInheritance($true, $true)
$spoList.Update()

$spoList.Context.Load($spoList)
$spoList.Context.ExecuteQuery()

 

Highlighted
Highlighted
This works for web as well
$web.BreakRoleInheritance($true, $false)
$web.Update()
$web.Context.Load($web)
$web.Context.ExecuteQuery()