Update All List Items Using PowerShell

Scenario:

You added a new column and need to update that column for every item in a list or library.

Solution:

Here is an example PowerShell script that can be used to update one or more columns for every single item in a list.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

function UpdateColumn()
{
#URL where the list or library lives
$WebURL = "http://sp2013/subsite"

#name of that list or library
$listName = "Documents"

#get the SPWeb object and save it to a variable
$webDestination = Get-SPWeb -identity $WebURL
$list = $webDestination.Lists[$listName]

#array of all items
$items = $list.Items

foreach ($item in $items)
{
Write-Output $item["FileLeafRef"]

#change "Column" to internal name of your column
#change "Something" to the information you're updating that column with
$item["Column"] = "Something"
$item.Update()
}

if ($webDestination)
{
$webDestination.Dispose()
}
}

UpdateColumn

Remember: change $WebURL to the URL of the site or subsite where the list or library lives, change “Column” in $item[“Column”] to your column’s internal name, and change “Something” to whatever information you want to update that column with.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s