How to Add a Custom Action in SharePoint using PowerShell?

Requirement: Add Custom Action using PowerShell in SharePoint.

PowerShell to Create User Custom Action in SharePoint:

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

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Set Site variable
$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 = ""
        $UserCustomAction.Description  = "Crescent Inc. Support Center"
        Write-Host -f Green "Custom Action Added Successfully!"
        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 my another post to add user custom action in SharePoint Online Add Custom Action using PowerShell in SharePoint Online

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply