Here we will see how to update all the list items in a list when a requirement of such comes in.
I have a PowerShell script here that you just need to add using Notepad and save it as a .ps1 file. In this script I am updating a choice field from a look up field.
- Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
- $webURL = “Your Site Url”
- $listName = “Name of your list”
- $web = Get-SPWeb $webURL
- $list = $web.Lists[$listName]
- $items = $list.items
- Foreach($item in $items)
- $prim = $item[“Look Up Column field”]
- write-host “Null”
- $trim = $prim.split(‘#’)
- write-host $trim
- $item[“choice field”] = $trim
- write-host $item[“Your Result You want to see”]
How to run
- You need to change the fields Site Url, List Name and Fields.
- You might have a question, why am I using a split function?
The field value when fetched from a look up field has characters like “1,#”. Using split we eliminate that extra data by giving us a correct variable.
- Run the SharePoint PowerShell as Administrator
- Run the .ps1 file
It will be executed and you will see the updated field values.
Here is a time saver article for my readers. Keep learning.