SharePoint Online: Remove Custom Action Using PowerShell CSOM

Requirement: Delete a Custom Action in SharePoint Online using PowerShell.

SharePoint Online: PowerShell to Remove Custom Action

Here is the PowerShell CSOM script to remove custom action:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Set parameter values
$CustomActionTitle = "SharePoint Admin Center"
    #Get Credentials to connect
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials

    #Get All Custom Actions
    $Web = $Ctx.Web
    $UserCustomActions= $Web.UserCustomActions

    #Get Custom Action(s) to delete
    $CustomActions = $UserCustomActions | Where { $_.Title -eq $CustomActionTitle }

    If($CustomActions -ne $Null)
        #Delete all custom actions
        $CustomActions | ForEach-Object {
            #Remove the custom action
            Write-Host -f Green "Custom Action '$($_.Name)' Deleted Successfully!"
         write-host -f Yellow "Custom Action Does not Exist!"
Catch {
        write-host -f Red "Error Removing Custom Action!" $_.Exception.Message

This deletes all custom actions with the provided title. You can get and delete them using their name, ID, or other parameters as well.

PnP PowerShell to Delete a Custom Action in SharePoint Online

Use the Remove-PnPCustomAction PnP cmdlet to remove a custom action in SharePoint Online.

#Config Variables
$SiteURL = ""

#Connect to SharePoint Online Site
Connect-PnPOnline -Url $SiteURL -Interactive

#Get Custom Actions

#Remove Custom Action
Remove-PnPCustomAction -Identity "SharePoint Admin Center" -Force

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *