Add Custom Ribbon Items To List Forms On SharePoint Using CSOM PowerShell


In this article, you will learn- how to add custom ribbon items (user actions) for various list forms, using CSOM Powershell on SharePoint 2013 / SharePoint online sites. The list forms considered are new form, display form, and edit form.

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.

  1. Add-Type -Path

  2. "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"

  3. Add-Type -Path

  4. "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

  5. Add-Type -Path

  6. "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.

  1. $siteURL = ""

  2. $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. 

  1. # Not required for on premise site - Start

  2. $userId = ""

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

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

  5. $ctx.credentials = $creds  

  6. # 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.

  1. # Credentials for on premise site - Start

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

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

  4. $ctx.Credentials = $creds 

  5.  # Credentials for on premise site - End