Add custom action with add-pnpcustomaction

Brass Contributor


I'm trying to hide the delete button in SharePoint Online list ribbon; I tried with custom action and powershell but I'm blocked (see SPO custom action to hide delete button - Microsoft Tech Community ).


With other research I find that, maybe, is possible to add a custom action with the powershell cmdlet add-pnpcustomaction of Pnp.PowerShell module; I have seen the syntax of the cmdlet but I don't understand some thing; I have a list, only a SPO list, where I want to apply the custom action: is it possible?

Say I have the where I have some lists, but I want to hide the delete button in the mytestlist: how to reference it in the command?


From some sample found online and also from the documentation sample I write something like this:


Connect-PnPOnline -Url "" -Interactive
$cUIExtn = "<CommandUIExtension><CommandUIDefinitions><CommandUIDefinition Location=""Ribbon.ListItem.Manage.Delete"" /></CommandUIDefinition></CommandUIDefinitions></CommandUIExtension>"
Add-PnPCustomAction -Name 'HideDeleteButton' -Title 'HideDeleteButton' -Location 'CommandUI.Ribbon' -RegistrationType List -Sequence 10000 -RegistrationId 101 -CommandUIExtension $cUIExtn


But, my 2 questions are:

  1. is it correct
  2. how or where reference the list?

Any help is appreciated.





1 Reply

Hi @Marco Mangiante,


You can hide actions in command bar in modern experience using View formatting. More information about this can be found here and here.


To hide the Delete button from the commandbar, the view formatting code should be as follows:

  "$schema": "",
  "commandBarProps": {
    "commands": [
        "key": "delete",
        "hide": true


Note: this is hiding the delete button from command bar, but still will be shown in the file/item context menu. If needed to be removed completely, I would prefer then controlling this using permissions by creating a new permission level, i.e., to allow users to create, and edit items, but not to delete items.