Wednesday 4 June 2014

List Item update using PowerShell / Replace list items using PowerShell

Replace List Items using PowerShell.

Item.Update()updates the " Modified "and "Modified By" fields as per the current logged in user and current server time. It also updates the version of the item if the Versioning option is Enabled in the List.

Item.SystemUpdate() -  If a user wishes he doesn't require to update Modified ", "Modified By" and  Version then user can for Systemupdate.


cls

Add-PSSnapin "Microsoft.SharePoint.Powershell"

$web =Get-SPWeb "http://weshare.sedwdev.local/sites/Russian/"

$list= $web.Lists.TryGetList("TestList")

$web.AllowUnsafeUpdates=$true

foreach($item in $list.Items)
{

$item["LinkData"] = $item["LinkData"].Replace("google","SharePoint2013")
$item["Editor"]=$item["Editor"]
$item["Modified"]=$item["Modified"]
$item.SystemUpdate();
}

#$list.Update();
Write-Host "Updated values in the list iteams are"

foreach($item in $list.Items)
{
$item["LinkData"]
}


OutPut :





No comments:

Post a Comment