How to add column in to List using Power Shell

Advertisement
In this Post we are able to show, how to add the “Multi Choice” column   to the Particular list and also we can check the condition that column is available in that list or not.
In our Example we created a List with Name “SharePoint List” using power shell created a column and adding the Values.

Add-PSSnapin Microsoft.SharePoint.PowerShell
#Get the Site URL
$weburl = Get-SPWeb "http://dotnetsharepoint.com/sites/SharePoint/SharePoint2013"
#Get the List Name
$list = $weburl.lists["SharePoint List"]
#check condition field is available or not
if($list.Fields.ContainsField("SharePoint") -eq $true)  {
      Write-Host  "FieldName already avilable in the List"
 }
 else
 {
 #Add New choice field to the list
$list.Fields.Add("SharePoint", [Microsoft.SharePoint.SPFieldType]::Choice,
$false)
#Add Choices to the field
$ChoiceField = $list.Fields.GetField("SharePoint")
#Get the field #Required Field
$ChoiceField.Required = $true
#Set Default value
$ChoiceField.DefaultValue = “SharePoint2013"
#Allow Fill-in Choices
$ChoiceField.FillInChoice = $false
#Add the Drop down choice values
$ChoiceField.Choices.Add("SharePoint2013")
$ChoiceField.Choices.Add("SharePoint2010")
$ChoiceField.Choices.Add("SharePoint2007")
#Commit changes
$ChoiceField.update()
$list.update()
}

OutPut:



SharePoint Online Real Time Training Contact: JLAKSHMITULASI@GMAIL.COM
Advertisements
SHARE

Lakshmi Tulasi Jasti

  • Image
  • Image
  • Image
  • Image
  • Image
    Blogger Comment
    Facebook Comment

0 comments:

Post a comment