The powershell script does the following functionalities,
- Loops through all the lists in the given site collection.
- Filters the list based on document library.
- Finds the specific/given list given in the script.
- Loops through all the items in the given list.
- Searches for a current value in one of the column for the list.
- 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.
- $LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
- $LogFile = ".\EditListItemPatch-$LogTime.rtf"
-
- # Add SharePoint PowerShell Snapin
-
-
- if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
- Add-PSSnapin Microsoft.SharePoint.Powershell
- }
-
- $scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
- Set-Location $scriptBase
-
-
- #Deleting any .rtf files in the scriptbase location
- $FindRTFFile = Get-ChildItem $scriptBase\*.* -include *.rtf
- if($FindRTFFile)
- {
- foreach($file in $FindRTFFile)
- {
- remove-item $file
- }
- }
-
-
- start-transcript $logfile
-
- $siteURL = read-host "Enter the site collection URL "
- $sitecollection = get-spsite $siteURL
- foreach($web in $sitecollection.allwebs)
- {
- write-host $web.url -fore yellow
- $lists = $web.lists
- foreach ($list1 in @($lists))
- {
- if ($list1.BaseType -eq [Microsoft.SharePoint.SPBaseType]::DocumentLibrary)
- {
- $list = $web.Lists[$list1.title]
-
-
- if($list.title -eq "TestList")
- {
- write-host $list.title -fore green
- $items = $List.items
-
- foreach($item in @($items))
- {
- ##########Put in your logic here###########################
- $value = $item["ColumnName"]
- write-host $value
-
- if($value -eq "Test")
- {
- $NewValue = "Test1"
- $item["ColumnName"] = $NewValue
-
- }
- ##########Put in your logic here###########################
- $item.update()
- }
- $list.update()
- }
- }
- }
- }
-
- stop-transcript