Add Custom Tabs and Groups to the Ribbon on SharePoint using CSOM PowerShell

In this post, you will learn how to add custom ribbon tabs, ribbon groups and ribbon items (user actions) for for list using CSOM Powershell on SharePoint 2013 / SharePoint 2016 / SharePoint online sites.

Steps Involved: The following prerequisites are required to be executed, before going for any operations, using CSOM PowerShell on SharePoint sites.

  • Add the references, using the Add-Type command with the necessary reference paths. The necessary references are Client.dll, Client.Runtime.dll and publishing.dll.

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"

Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Publishing.dll"

  • Initialize the client context object with the site URL.

$siteURL = ""

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)  

  • If you are trying to access SharePoint Online site, then you need to setup the site credentials with the credentials parameter and load it to the client context. 

# Not required for on premise site - Start

$userId = "" $pwd = Read-Host -Prompt "Enter password" -AsSecureString  

$creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($userId, $pwd)  

$ctx.credentials = $creds  

# Not required for on premise site - End

  • If you are trying to access the SharePoint on premise site, then the credentials parameter is not required to be set to the context but you need to run the code on the respective SharePoint Server or you need to pass the network credentials and set the context.

# Credentials for on premise site - Start

$pwd = Read-Host -Prompt "Enter password" -AsSecureString  

$creds = New-Object System.Net.NetworkCredential("domain\userid", $pwd)  

$ctx.Credentials = $creds