Add And Remove Operation Of Custom Action In SharePoint Site Using PnP PowerShell

In this blog, we will see how we can add a custom action in a SharePoint site using PnP PowerShell. Also, we will see how we can get a particular custom action and remove it from SharePoint sites using PnP PowerShell.

Add Custom Action

In the following example, I have added a personal action menu in my SharePoint site.

Add And Remove Operation Of Custom Action In SharePoint Site Using PnP PowerShell

Get Particular Custom action and remove it from the site

You can get all user custom actions present under a site using the following script:

“Get-PnPCustomAction”

In the following example, it shows how you can get particular custom action and remove it from a SharePoint site. In this particular example it removes all custom actions that are ScriptLinks:

“Get-PnPCustomAction -Scope All |? Location -eq ScriptLink | Remove-PnPCustomAction”

The code block for this is mentioned below.

Connect-PnPOnline –Url https://yoursite.sharepoint.com –Credentials (Get-Credential)

<#Add user custom action in your SharePoint site.

Here it adds my custom action under personal action menu#>

Add-PnPCustomAction -Name 'MyCustomActionMenu' -Title 'My Custom Menu' -Description 'Adds custom action to personal action menu' -Group 'PersonalActions' -Location 'Microsoft.SharePoint.StandardMenu' -Sequence 3010 -Url 'javascript:alert("My custom action menu");'

  1. <#Get all custom action present under a site#>  
  2. Get-PnPCustomAction  
  3. <#Removes all custom actions that are ScriptLinks#>  
  4. Get-PnPCustomAction -Scope All |? Location -eq ScriptLink | Remove-PnPCustomAction