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.
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