I want to create a boolean site column (yes/no field) througn pnp power shell. I used Add-PnPField command, but how to set default value to "no"
2 Answers
After you create your field using Add-PnPField, you need to get that field using Get-PnPField and set the default value as below:
$field = Get-PnPField -List CustomList -Identity "BoolField"
$field.DefaultValue = "0"
$field.Update()
Invoke-PnPQuery
Also, you can use PnPFieldFromXml itself to create a boolean field with No as default value as :
$fieldXml = "<Field Type='Boolean' Name='TestBool' StaticName='TestBool' DisplayName='Test Bool'><Default>0</Default></Field>"
Add-PnPFieldFromXml -FieldXml $fieldXml
References - Add-PnPFieldFromXml
-
hey @gokulnath, hope that helped you. You can accept this answer which will earn you the learner badge as well as remove it from the unanswered questions list ! Cheers, thanks !Gautam Sheth– Gautam Sheth2018-08-28 05:41:28 +00:00Commented Aug 28, 2018 at 5:41
Meanwhile you can add boolean values with PNP
$DisplayName = "Win"
$PNPField = Add-PnPField -List $List -DisplayName $DisplayName -InternalNameDisplayName -Type Boolean -AddToDefaultView
Source: https://sposcripts.com/add-sharepoint-columns-with-powershell/#Add_Boolean_Column