Created
January 8, 2019 13:57
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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
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}