How to Add a Custom Action in SharePoint using PowerShell?

Requirement: Add Custom Action using PowerShell in SharePoint.

PowerShell to create a User Custom Action in SharePoint:

Here is the PowerShell to add user custom action – which adds a link to the site settings menu.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

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

Try {
    #Get the Web
    $Web = Get-SPWeb $SiteURL
 
    #Check if the Custom Action Exists already
    $CustomAction = $web.UserCustomActions | Where { $_.Title -eq $CustomActionTitle }

    If($CustomAction -eq $Null)
    {
        #Add new custom action
        $UserCustomAction = $web.UserCustomActions.Add()

        #Set the Properties of the custom action
        $UserCustomAction.Title = $CustomActionTitle
        $UserCustomAction.Location = "Microsoft.SharePoint.StandardMenu" 
        $UserCustomAction.Group = "SiteActions" #Site Settings Menu
        $UserCustomAction.Sequence = 1000
        $UserCustomAction.Url = "https://intranet.crescent.com/support/"
        $UserCustomAction.Description  = "Crescent Inc. Support Center"
        $UserCustomAction.Update()
 
        Write-Host -f Green "Custom Action Added Successfully!"
    }
    Else
    {
        write-host -f Yellow "Custom Action Already Exists!"
    } 
} Catch {
    Write-Host -ForegroundColor Red "Error:" $_.Exception.Message
}

And the result of user custom action:

sharepoint add custom action powershell

Here is another post to add user custom action in SharePoint Online: How to Add Custom Action using PowerShell in SharePoint Online?

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

2 thoughts on “How to Add a Custom Action in SharePoint using PowerShell?

Leave a Reply

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