Friday, August 16, 2013

Create SharePoint Choice Field (Site Column) using PowerShell

Start-SPAssignment -Global
$url = "siteurl"
$web = get-spweb $url

$fieldName = "Surya"
$field = $web.Fields[$fieldName]

 if($field -ne $nul)
      Write-Host $field.Title "Field already avilable in the site"

#There are 2 ways to create a field.
#First Apporach
      Write-Host "no fields exist with this name. creating..."
      $web.fields.add($fieldName, "Choice", $true)
      $field = $web.fields.getfield($fieldName)
      $field.Group = "Custom Columns"
     Write-Host "Field Created"

#Second Apporach

      $suryafield = "<Field Type='Choice' DisplayName='Surya' Required='TRUE' Format='Dropdown' Group='Custom Columns'
      FillInChoice='FALSE' StaticName='Surya' Name='Surya'>
  Write-Host "Field Created"

 Stop-SPAssignment -Global

No comments:

Post a Comment