1

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 2

6

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

Create fields using CSOM

1
  • 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 ! Aug 28, 2018 at 5:41
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.