1

I would like to add multiple User Custom Actions on several sites using PowerShell. The custom actions must be added in the top ribbon that is visible when selecting a list item. Is that even possible? When looking at SPList userCustomActions property, it is readonly, according to MSDN . Am I taking the wrong path? The property is readonly but the custom actions are there, so they must have been added.

So far I've been there.

$w = get-spweb $webUrl;
$l = $w.lists[$listTitle];
$userCustomActions = $l.userCustomActions;

Of course, custom Actions can be added via JS, C# + feature, SharePoint Designer. But I can't use those methods, So I'm only interested in PowerShell procedures.

1

You can use the UserCustomActions.Add() method to add the custom action.

Try and modify the below code:

$web = get-spweb $webUrl;
$list = $web.Lists[$listTitle];
$action = $list.UserCustomActions.Add();

$action.Url = "someurlhere";
$action.Location = "Ribbon.ListItem.Actions.Controls._children";
$action.Sequence = 85;
$action.Title = "Test Action";
$action.Description  = "Test Action description";

$action.Update();

MSDN - SPUserCustomActionCollection.Add

  • Thank you @Gautam. I realize that even if the code is not writing in PowerShell, (ex : C#, JavaScript) the methods exposed by objects, most of the time, have the same signature and can be used the same way. – ameliapond May 28 '17 at 18:36
  • 1
    Welcome, glad i could help :) , fyi - almost anything that's possible via c# ssom code is doable via powershell, just minor changes in syntax. – Gautam Sheth May 28 '17 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.