Add context menu to list item field by powershell

05/01/2016 01:18

List item context menu is bound to SharePoint 'Title' field by default. However, sometimes we don't have this field in our content type or we have the other reason to have context menu on the other field. Here is the powershell script, how to bind context menu to the other field.

 

Add-PSSnapin microsoft.sharepoint.powershell -ea 0

$webUrl = "https://yoursitecollection"
$listName = "MyListName"
$fieldName = "MyFieldInternalName" #field, where we want to bind context menu

$web = get-spweb $webUrl
$list = $web.Lists[$listName]
$field = $list.Fields.TryGetFieldByStaticName($fieldName);

$field.ListItemMenuAllowed = "Required"; #"Allowed" is default
$field.Update();