We are using this below script to add new values to our choice column, but need the option to sort the SharePoint list column choice values ascending. There are over 150 values, and just putting new values on the end/bottom of the dropdown isn't user friendly.
Connect-PnPOnline -Url "https://MySite/sites/Sandbox" -UseWebLogin
$field = Get-PnPField -List aaa-f31e-4cc0-b193-bbb -Identity Schedule
[xml]$schemaXml = $field.SchemaXml
$varNewChoice = $schemaXml.CreateElement("CHOICE")
$varNewChoice.InnerText = "Thursday"
$schemaXml.Field.CHOICES.AppendChild($varNewChoice)
Set-PnPField -List aaa-f31e-4cc0-b193-bbb -Identity Schedule -Values @{SchemaXml=$schemaXml.OuterXml}
*** Update >> Was able to get this code to both add value and sort:
Connect-PnPOnline -Url "https://ourtenant.sharepoint.com/sites/Sandbox" -UseWebLogin
$field = Get-PnPField -List "Space Request Form" -Identity "Schedule"
$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 += "Bentley"
$fieldChoice.Choices = $choices | Sort-Object
$fieldChoice.UpdateAndPushChanges($true)
Invoke-PnPQuery