I have a few hundred sites in which I have a list (doclibrary) where I use a choice field which has 8 choices. Now I need to delete a choice and rename (or delete and add a new one) another choice. I created this powershell script sofar:
$username = "blabla"
$password = "bla"
$url = "https://blabla.sharepoint.com/"
$securePassword = ConvertTo-SecureString $Password -AsPlainText -Force
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$ctx.Credentials = $credentials
if (!$ctx.ServerObjectIsNull.Value)
{
Write-Host "Connected to SharePoint Online site: '$Url'" -ForegroundColor Green
}
$rootWeb = $ctx.Web
$sites = $rootWeb.Webs
$ctx.Load($rootWeb)
$ctx.Load($sites)
$ctx.ExecuteQuery()
foreach($site in $sites)
{
$ctx.Load($site)
$ctx.ExecuteQuery()
Write-Host $site.Title "-" $site.Url
$olist = $site.get_lists().getByTitle('CustomList');
$fieldColl = $oList.Fields;
$ctx.Load($fieldColl);
$ctx.ExecuteQuery();
foreach ($fieldTemp in $fieldColl)
{
if ($fieldTemp.InternalName.Contains("QuestionType"))
{
Write-Host $fieldTemp.InternalName
$FieldTemp.choices
$FieldTemp.choices.remove("General")
$FieldTemp.update()
}
}
} On the remove command I get an error "Collection was of a fixed size".
What can I do to achieve my goal?
Thanks, Mike