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
$SiteURL="http://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 = "http://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 my another post to add user custom action in SharePoint Online Add Custom Action using PowerShell in SharePoint Online
How to Add a Custom Action in SharePoint using PowerShell? How to Add a 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.