Often we are faced with situation where in we need to update certain list values to reflect new values 🙂 this time we had a requirement wherein we needed to replace item values in a list with an updated value, though there are many ways to do it for instance using sharepoint API or object model & use code to get it done 🙂 However interestingly we this time i thought of using powershell command to perform the same & i had to write a very small script to get the job done & here it goes
$sites = Get-SPSite ‘http://ServerName/PWA’ | Get-SPWeb -Limit All
Foreach($site in $sites)
{
$site.title
$list = $site.Lists.TryGetList(“Risks”)
#Get all items in this list and save them to a variable
$items = $list.items
Foreach($item in $items)
{
#If the “Column” column value equals “Specified Value” Update with new Value
if($item[“Column Name”] -eq “Specified Value”)
{
#Change the value of the “Column Name” column
$item[“Column Name”] = “New Value”
#Update the item
$item.Update()
#Use this Optional Code to add new column to current list
#$myField = $list.Fields.Add(“Test5”, “Text”, 0)
#$list.Fields[$myField].Update()
#Write-host -ForegroundColor green “Column has been added”
}
}
}
My partner and I absolutely love your blog and find many of your post’s to be what precisely I’m
looking for. Does one offer guest writers to write content for yourself?
I wouldn’t mind producing a post or elaborating on a lot of the subjects you write concerning here.
Again, awesome web log!