Jesper M. Christensen

SharePoint and Security

Bulk change list item metadata in SharePoint 2010


Sometimes we need to change one or multiple items in a SharePoint list, and this PowerShell script helps us accomplish this task very easy:

Change a single item (with a known ID)

$SPAssignment = Start-SPAssignment
$SPWeb = Get-SPWeb http://intranet.domain.local/sitename -AssignmentCollection $spAssignment
$SPList = $SPWeb.Lists[“Contacts”]
$SPItem = $SPList.GetItemById(“37”)
$SPItem[“Company”] = “New value”
$SPItem.Update()
Stop-SPAssignment $SPAssignment

 

Change multiple items (with a known field value)

$SPAssignment = Start-SPAssignment
$SPWeb = Get-SPWeb http://intranet.domain.local/sitename -AssignmentCollection $spAssignment
$SPList = $SPWeb.Lists[“Company”]
$SPItems = $SPList.Items | Where { $_[“Company”] -eq “Old value” }
foreach($item in $SPItems){
$item[“Konsulent”] = “New value”
$item.Update()
}
Stop-SPAssignment $SPAssignment


 

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: