I want to delete and add new choice fields in SharePoint Online list but only with PnP PowerShell.
Can you please suggest how to access choices of drop down field with PnP PowerShell?
We can modify the options of a choice field by modifying the schema xml of the field
Let say the field Fruit has 2 options, Apple and Orange and we want to add Banana to the list
First we get the schema xml of the field
$field = Get-PnPField -List 20559154-6a7e-4e67-b10b-a12bbc943152 -Identity Fruit
[xml]$schemaXml = $field.SchemaXml
The schema xml of the field should looks like this
<Field DisplayName="Fruit" FillInChoice="FALSE" Format="Dropdown" Title="Fruit" Type="Choice" ID="{98354d16-9929-4a1f-a97a-347694aaadad}" SourceID="{20559154-6a7e-4e67-b10b-a12bbc943152}" StaticName="Fruit" Name="Fruit" ColName="nvarchar4" RowOrdinal="0">
<CHOICES>
<CHOICE>Apple</CHOICE>
<CHOICE>Orange</CHOICE>
</CHOICES>
</Field>
Then we may add the new choice, Banana, to the schema
$banana = $schemaXml.CreateElement("CHOICE")
$banana.InnerText = "Banana"
$schemaXml.Field.CHOICES.AppendChild($banana)
Finally we can update the schema xml of the field
Set-PnPField -List 20559154-6a7e-4e67-b10b-a12bbc943152 -Identity Fruit -Values @{SchemaXml=$schemaXml.OuterXml}
Now the field should have 3 options Apple, Orange and Banana in the list
Ref link - https://github.com/SharePoint/PnP-PowerShell/issues/1846