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 - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world 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 *