Interview Questions administrator

Best SharePoint administrator Interview Questions and Answers with topic wise:


Recycle Bin | MMS | ManagedVsCrawledProperties |

Thursday, September 25, 2014

create sharepoint boolean field using powershell script

Please visit my below post which helps on how to create sharepoint list using powershell script:
Create sharepoint list using powershell script

Note: By default, below method sets the boolean field as Yes(1). If you want as No(0), provide the 0 value to the "DefaultValue"
****************************************************************************************
$lncustomListName listName
$docSite = new-object Microsoft.SharePoint.SPSite($siteURL)
$docWeb = $docSite.OpenWeb()

/* To create Boolean field */
Add-SPBooleanField -listName $lncustomListName -Name EmailFlag -DisplayName EmailFlag -Required TRUE -DefaultValue 1

/* Method to create boolean field */
function Add-SPBooleanField([string]$listName, [string]$DisplayName, [string]$Name, [string]$Required,[string]$DefaultValue)
{
  $OpenList = $docWeb.Lists[$listName]
  $fldXml = "<Field Type='Boolean' DisplayName='"+$DisplayName +"' Required='"+ $Required +"' Name='"+ $Name +"'>
           <Default>$DefaultValue</Default>
           </Field>"
  $OpenList.Fields.AddFieldAsXml($fldXml,$true,
  [Microsoft.SharePoint.SPAddFieldOptions]::AddFieldToDefaultView)
}

*****************************************************************************************
Please let me know if faced any issues.

No comments:

Post a Comment