-
-
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.
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