Skip to content

Instantly share code, notes, and snippets.

@OlafD
Created January 8, 2019 13:57
Show Gist options
  • Save OlafD/2b00b8b89f9909199a51af8df71230bf to your computer and use it in GitHub Desktop.
Save OlafD/2b00b8b89f9909199a51af8df71230bf 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
@bwya77
Copy link

bwya77 commented Mar 14, 2021

I just wanted to comment if anyone else is trying to do this - You could grab existing values and add it to a long string, then comma separate everything

[system.string[]]$Users = "Bradley Wyatt","Jason Portillo"
Set-PnPField -List "Onboarding" -Identity "Copy_x0020_User" -Values @{Choices=$Users}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment