The powershell script does the following functionalities,
  1. Loops through all the lists in the given site collection.

  2. Filters the list based on document library.

  3. Finds the specific/given list given in the script.

  4. Loops through all the items in the given list.

  5. Searches for a current value in one of the column for the list.

  6. It replaces/sets the value for the column with the given new value only if it satisfies the given criteria.

#Loops through each items in the given list and locates the column name "ColumnName" and checks whether the value for that field is "Test", if so it replaces it with #"Test1" and updates the item and updates the list.

  1. $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
  2. $LogFile = ".\EditListItemPatch-$LogTime.rtf"
  3. # Add SharePoint PowerShell Snapin
  4. if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
  5. Add-PSSnapin Microsoft.SharePoint.Powershell
  6. }
  7. $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
  8. Set-Location $scriptBase
  9. #Deleting any .rtf files in the scriptbase location
  10. $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
  11. if($FindRTFFile)
  12. {
  13. foreach($file in $FindRTFFile)
  14. {
  15. remove-item $file
  16. }
  17. }
  18. start-transcript $logfile
  19. $siteURL = read-host "Enter the site collection URL "
  20. $sitecollection = get-spsite $siteURL
  21. foreach($web in $sitecollection.allwebs)
  22. {
  23. write-host $web.url -fore yellow
  24. $lists = $web.lists
  25. foreach ($list1 in @($lists))
  26. {
  27. if ($list1.BaseType -eq [Microsoft.SharePoint.SPBaseType]::DocumentLibrary)
  28. {
  29. $list = $web.Lists[$list1.title]
  30. if($list.title -eq "TestList")
  31. {
  32. write-host $list.title -fore green
  33. $items = $List.items
  34. foreach($item in @($items))
  35. {
  36. ##########Put in your logic here###########################
  37. $value = $item["ColumnName"]
  38. write-host $value
  39. if($value -eq "Test")
  40. {
  41. $NewValue = "Test1"
  42. $item["ColumnName"] = $NewValue
  43. }
  44. ##########Put in your logic here###########################
  45. $item.update()
  46. }
  47. $list.update()
  48. }
  49. }
  50. }
  51. }
  52. stop-transcript