Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ITProCorner/b5a35606d40cb4fa0aed5257ebb984a1 to your computer and use it in GitHub Desktop.

Select an option

Save ITProCorner/b5a35606d40cb4fa0aed5257ebb984a1 to your computer and use it in GitHub Desktop.
In SharePoint Online, add a new choice value to an existing choice field. The fieldname in the example is "MyChoiceField" with 3 very simple choices. A fourth choice is added by the script. A connection to the SharePoint site must be established.
$field = Get-PnPField -Identity "MyChoiceField"
$ctx = Get-PnPContext
$fieldChoice = [Microsoft.SharePoint.Client.ClientContext].GetMethod("CastTo").MakeGenericMethod([Microsoft.SharePoint.Client.FieldChoice]).Invoke($ctx, $field)
$ctx.Load($fieldChoice)
Invoke-PnPQuery
$choices = $fieldChoice.Choices
$choices += "FOUR"
$fieldChoice.Choices = $choices
$fieldChoice.UpdateAndPushChanges($true)
Invoke-PnPQuery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment