Interview Questions administrator

Best SharePoint administrator Interview Questions and Answers with topic wise:


Recycle Bin | MMS | ManagedVsCrawledProperties |

Friday, November 14, 2014

SharePoint choice field using powershell

$docSite = new-object Microsoft.SharePoint.SPSite($siteURL)
$docWeb = $docSite.OpenWeb()
$lncustomListName listName
$CustomfieldName = "MyChoiceColumn"

/* To create choice field */
Add-SPMultiChoiceField -listName $lncustomListName

/* Method to create choice field */
function Add-SPMultiChoiceField([string]$listName)
{
  $OpenList = $docWeb.Lists[$listName]
  $multiChoiceCol = "<Field Name='"+ $CustomfieldName +"' Type='MultiChoice' FillInChoice='FALSE' DisplayName='"+ $CustomfieldName +"'><Default>MyChoice1</Default><CHOICES><CHOICE>MyChoice2</CHOICE><CHOICE>ERM</CHOICE><CHOICE>MyChoice3</CHOICE></CHOICES></Field>"
 $OpenList.Fields.AddFieldAsXml($multiChoiceCol,$true,
 [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView) 
}

No comments:

Post a Comment