i have document library in sharepoint 2010 and i want to update a field values based on some conditions .
I need that every parentid has some documents and i want to update those prosessnos which has null value, this is only sample data ,actually in live it has 5000 documents
ex if parentid 100 has 3 documents i want to update processno like 1,2,3
and next parentid 101 has 2 documents i wnt to update processno like 1,2
i need output like this after update
DoucmentID ParentID ProcessNo
1000 100 1
1001 100 2
1002 100 3
2000 101 1
2001 101 2
i created below function but it did not update values properly
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
$webURL = "http://tspmcwfe:91" $listName = "Courts"
Get the SPWeb object and save it to a variable
$web = Get-SPWeb $webURL
$list = $web.Lists[$listName] $items = $list.items
$internal_counter = 1 $flagPID =1 $vPID=0
Go through all items
foreach($item in $items)
{
$vPID=0
$PID = $item["ParentID"] -not $null $Pno = $item["Processno"] -match $null $between = $item["ParentID"] -match $vPID
if($PID -eq $true -and $Pno -eq $true)
{
if($between -eq $true) {
$item["ProcessNo"] = $internal_counter $vPID=$item["ParentID"] } else { $item["ProcessNo"] = $internal_counter
$vPID=$item["ParentID"] }
$internal_counter++
$item.Update()
} }
$web.Dispose()