PowerShell CSOM - Add custom user action



There are multiple approaches to add custom user action to your Office 365 SharePoint site In this post I'm using the Powershell CSOM, and will be creating a simple custom action to show in ribbon control for custom list template. The ribbon control custom action on click will show an alert with the number of items in the custom list. First, we'll start with adding DLL references for the SharePoint Client, which will help with the remote API calls.


Next, lets get started with creating the client context and getting the existing user custom actions. Also check if the custom action already exists, and delete if already available.

Lets initialize the properties for the new custom action, make sure that in CommandUIExtension the quotesare escaped properly. Also exercise care with the line breaks, when you are adding a complex JavaScript inside that block. If not it may prove costly later.

Lets put altogether, when executed you'll be prompted for web site url, username and password. Provide the web site where the custom action as to be added. To validate go to any custom list and in the ribbon click "Get Items Count" button, you'll prompted with number of items in that list.


Happy coding! Peace!!

Comments