Update All Items in a SharePoint List using PowerShell

Use these PowerShell scripts to update all items in SharePoint lists:

SharePoint PowerShell script to update all items in a list:

Requirement is to update all items in a SharePoint list using PowerShell script:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

### Variables ###
#Site URL and List names
$SiteURL = "http://intranet.crescent.com/"
$ListName = "Business Contacts"                 

#Get site and List objects
$web = Get-SPWeb $SiteURL
$List = $web.Lists.TryGetList($ListName)

if($List -ne $null)
    {    
        #Get all List items
        $ListItems = $list.Items
        
        #Iterate through each item
        Foreach($item in $ListItems)
        {
            #To update a particular field, 
            $item[$FieldName]= NewValue;

            #sharepoint powershell update all items in list
            $item.update()
        }
    }
#dispose web object
$web.Dispose() 

Filter and Update all documents in a SharePoint Library:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

### Variables ###
#Site URL and List names
$SiteURL = "http://intranet.crescent.com/Sites/Sales"
$ListName = "Sales Proposals" 
#Column to update
$FieldName ="Sales Category"
#Field old and new values
$OldValue = "Software"
$NewValue="Applications"

#Get site and List objects
$web = Get-SPWeb $SiteURL
$List = $web.Lists.TryGetList($ListName)

if($List -ne $null)
{
	#Get all documents with .docx extension
	$DocsCollection = $List.Items | where {$_.Name -match ".docx"}
	
	#Iterate through each document
	foreach ($Doc in $DocsCollection)
	{
		#Change Category Metadata
		if($Doc[$FieldName] -eq $OldValue)
		{
			$Doc[$FieldName] = $NewValue

			#Perform a system update to keep versions, Modified by metadata intact
			$Doc.SystemUpdate($false)
			write-host "Updated an item at: $($doc.URL)"
		}
	}
}

#dispose web object
$web.Dispose() 

This PowerShell script selectively updates all document’s metadata, residing in a library – Including the one inside folders.

Here is an another trick to trigger update on multiple documents in SharePoint:

  • Navigate to your document library
  • Select required documents >> Click on “Check Out” button from ribbon
  • Click on “Check-in”
Update All Items in a SharePoint 2013

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply