SOLVED

How to remove all list item permissions using PnP Powershell

%3CLINGO-SUB%20id%3D%22lingo-sub-2076138%22%20slang%3D%22en-US%22%3EHow%20to%20remove%20all%20list%20item%20permissions%20using%20PnP%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2076138%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20like%20to%20remove%20all%20permissions%20of%20a%20list%20item%20using%20PnP%20Powershell%3C%2FP%3E%3CP%3EI%20have%20tried%20this%20command%20%3A%26nbsp%3BSet-PnPListItemPermission%26nbsp%3B%3CSPAN%3E-Identity%20%24item.id%26nbsp%3B%3CSPAN%20class%3D%22hljs-parameter%22%3E-User%3C%2FSPAN%3E%20%3CSPAN%20class%3D%22hljs-string%22%3E'user%40contoso.com'%3C%2FSPAN%3E%20-AddRole%20%22Contribute%22%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EHowever%26nbsp%3B%3CSPAN%3Ethe%20user%20running%20the%20script%2Fcommand%20was%20also%20added%20with%20Full%20Control%20permissions.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EIs%20there%20any%20other%20way%20to%20remove%20all%20existing%20permissions%20for%20a%20list%20item%20using%20PnP%20Powershell%20%3F%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThanks%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2076138%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2077574%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20remove%20all%20list%20item%20permissions%20using%20PnP%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2077574%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F754982%22%20target%3D%22_blank%22%3E%40Arioule%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EIt's%20normal%20behavior%26nbsp%3Bfor%20the%20current%20user%20to%20remain%20in%20the%20list%20item%20permissions%20when%20the%20inheritance%20is%20broken%20and%20cleared%20on%20a%20list%20item%20to%20ensure%20that%20at%20least%20one%20user%20still%20has%20access.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ETry%20this%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EFirst%20assign%20permissions%20to%20a%20user%3A%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3ESet-PnPListItemPermission%20-List%20'ListName'%20-Identity%201%20-User%20'user%40contoso.com'%20-AddRole%20'Contribute'%20-ClearExisting%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThen%20remove%20permissions%20of%20the%20user%20running%20script%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3ESet-PnPListItemPermission%20-List%20'ListName'%20-Identity%201%20-User%20%22scriptuser%40contoso.com%22%20-RemoveRole%20%22Full%20Control%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EReference%3C%2FSTRONG%3E%3A%26nbsp%3B%3CA%20title%3D%22Set-PnPListItemPermission%20-ClearExisting%20adds%20the%20user%20running%20the%20script%20with%20full%20control%22%20href%3D%22https%3A%2F%2Fgithub.com%2Fpnp%2FPnP-PowerShell%2Fissues%2F2185%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESet-PnPListItemPermission%20-ClearExisting%20adds%20the%20user%20running%20the%20script%20with%20full%20control%3C%2FA%3E%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CHR%20%2F%3E%3CP%3EPlease%20click%20%3CSTRONG%3EMark%20as%20Best%20Response%3C%2FSTRONG%3E%20if%20my%20post%20helped%20you%20to%20solve%20your%20issue.%20This%20will%20help%20others%20to%20find%20the%20correct%20solution%20easily.%20It%20also%20closes%20the%20item.%20If%20the%20post%20was%20useful%20in%20other%20ways%2C%20please%20consider%20giving%20it%20%3CSTRONG%3ELike%3C%2FSTRONG%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2080069%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20remove%20all%20list%20item%20permissions%20using%20PnP%20Powershell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2080069%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F373269%22%20target%3D%22_blank%22%3E%40ganeshsanap%3C%2FA%3E%26nbsp%3BThanks%20for%20your%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Hi,

 

I would like to remove all permissions of a list item using PnP Powershell

I have tried this command : Set-PnPListItemPermission -Identity $item.id -User 'user@contoso.com' -AddRole "Contribute"

However the user running the script/command was also added with Full Control permissions.

 

Is there any other way to remove all existing permissions for a list item using PnP Powershell ?

 

Thanks

2 Replies
Best Response confirmed by Arioule (Occasional Contributor)
Solution

@Arioule 

 

It's normal behavior for the current user to remain in the list item permissions when the inheritance is broken and cleared on a list item to ensure that at least one user still has access.

 

Try this:

 

First assign permissions to a user:

 

 

Set-PnPListItemPermission -List 'ListName' -Identity 1 -User 'user@contoso.com' -AddRole 'Contribute' -ClearExisting

 

 

Then remove permissions of the user running script:

 

 

Set-PnPListItemPermission -List 'ListName' -Identity 1 -User "scriptuser@contoso.com" -RemoveRole "Full Control"

 

 

ReferenceSet-PnPListItemPermission -ClearExisting adds the user running the script with full control  


Please click Mark as Best Response if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.