SharePoint Online: Add Custom Action using PowerShell

Requirement: Create Custom Action in SharePoint Online using PowerShell

How to Add Custom Action in SharePoint Online?

User custom action in SharePoint Online is a recommended way to customize the user interface, such as adding a new link to the Site Settings page, adding menu items, ribbon buttons-groups, inject JavaScript or CSS to SharePoint. Here is an example to add a custom action in SharePoint Online:

SharePoint Online Add Custom Action using PowerShell

Here is the PowerShell to Create Custom Action in SharePoint Online:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Set parameter values
$CustomActionTitle = "SharePoint Admin Center"
    #Get Credentials to connect
    $Cred= Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = $Credentials

    #Get Existing Custom Actions
    $Web = $Ctx.Web
    $UserCustomActions= $Web.UserCustomActions

    #Check if the CustomAction Exists already
    $CustomAction = $UserCustomActions | Where { $_.Title -eq $CustomActionTitle } | Select -First 1

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

        #Set the Properties of the custom action
        $UserCustomAction.Name = $CustomActionTitle
        $UserCustomAction.Title = $CustomActionTitle
        $UserCustomAction.Location = "Microsoft.SharePoint.SiteSettings"
        $UserCustomAction.Group = "SiteTasks" #Site Actions
        $UserCustomAction.Sequence = 1000
        $UserCustomAction.Url = ""    

        Write-Host -f Green "Custom Action Added Successfully!"
         write-host -f Yellow "Custom Action Already Exists!"
Catch {
        write-host -f Red "Error Adding Custom Action!" $_.Exception.Message

This Adds a custom action to create a link under site settings in SharePoint Online

sharepoint online add custom action powershell

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!

Leave a Reply

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