I have a Site Collection with many subsites that all have the same Custom List (CustomList1) and Choice Column (ChoiceColumn1 - List Columns not Site Columns). I successfully added a field value to ChoiceColumn1 under CustomList1 for the Site Collection but the update fails for SubSites under the Site Collection URL.
Code:
Add-PsSnapin Microsoft.SharePoint.PowerShell -erroraction silentlycontinue
$web = get-spweb https://webapp.domain.com/sites/sitecollection/
$list = $web.lists[“CustomList1”]
$choice = $list.fields[“ChoiceColumn1”]
$choice.choices
$choice.choices.add(“New Value”)
$choice.update()
If I change:
$web = get-spweb https://webapp.domain.com/sites/sitecollection/
To
$web = get-spweb https://webapp.domain.com/sites/sitecollection/subsite
It fails.
Error:
Cannot Index into a null value.
Exception calling "Update" with "0" argument(s): "The node to be inserted is from a different document context."
How can I update the Choice Column field value for all subsites under the Site Collection?