Introduction

Welcome readers to an article on updating list items in SharePoint 2013 and Office 365 using PowerShell.

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.

Script

  1. Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
  2. $webURL = "Your Site Url"
  3. $listName = "Name of your list"
  4. $web = Get-SPWeb $webURL
  5. $list = $web.Lists[$listName]
  6. $items = $list.items
  7. Foreach($item in $items)
  8. {
  9. $prim = $item["Look Up Column field"]
  10. if(!$prim)
  11. {
  12. write-host "Null"
  13. }
  14. else
  15. {
  16. $trim = $prim.split('#')[1]
  17. write-host $trim
  18. $item["choice field"] = $trim
  19. $item.Update()
  20. write-host $item["Your Result You want to see"]
  21. }
  22. }

How to run

It will be executed and you will see the updated field values.

Here is a time saver article for my readers. Keep learning.

Cheers!