Monday, November 4, 2013

Powershell script to go through all lists in a website and update the field value if a field exists

##Go through all lists in a website and update the field value if a field exists

 $web = get-spweb http://webSite/ITSprojects/ERP/

 foreach ($list in $web.lists)
 {
if( $list.Fields.ContainsField("Required for Round 6") -eq $true)
    {                                      
        Write-Host "Required for Round 6 found and updating value in " $list.title
$listItms = $list.Items
foreach ($item in $listItms)
{
$item["Required for Round 6"]="0";
$item.Update();
}
Write-Host "Required for Round 6 update completed-------" $list.title
    }
else
{
Write-Host "Required for Round 6 not found in " $list.title
}
if( $list.Fields.ContainsField("Round 6 Result") -eq $true)
    {                                      
        Write-Host "Round 6 Result found and updating value in " $list.title
$listItms = $list.Items
foreach ($item in $listItms)
{
$item["Round 6 Result"]="Not Tested";
$item.Update();
}
Write-Host "Round 6 Result update completed-------" $list.title
    }
else
{
Write-Host "Round 6 Result not found in " $list.title
}
}

No comments:

Post a Comment