Remove Custom Action in SharePoint using PowerShell

Requirement:  Remove a Custom Action in SharePoint using PowerShell

Delete Custom Action using PowerShell in SharePoint:
Here is how to remove custom action in SharePoint 2013 using PowerShell
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set Site variable
$SiteURL="http://intranet.crescent.com"
$CustomActionTitle ="Support Center"

Try {
    #Get the Web
    $Web = Get-SPWeb $SiteURL
 
    #Get the Custom Actions Filter by Title
    $CustomActions = $web.UserCustomActions | Where { $_.Title -eq $CustomActionTitle } | Select ID, Title

    If($CustomActions -ne $Null)
    {
        #Delete custom action(s)
        $CustomActions | ForEach-Object {
            #Remove the custom action
            $web.UserCustomActions.Item($_.Id).Delete()
            Write-Host -f Green "Custom Action '$($_.Title)' Deleted Successfully!"
        }
    }
    Else
    {
        write-host -f Yellow "Custom Action '$CustomActionTitle' Doesn't Exist!"
    } 
} Catch {
    Write-Host -ForegroundColor Red "Error:" $_.Exception.Message
}

To delete all custom actions from the given scope, simply remove the "Where" class from the script!

Here is my related post on deleting custom action in SharePoint Online: How to Delete a Custom Action in SharePoint Online using PowerShell
Remove Custom Action in SharePoint using PowerShell Remove Custom Action in SharePoint using PowerShell Reviewed by Salaudeen Rajack on July 10, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.