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

powershell update values

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)



$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"] }



} }


enter image description here

2 Answers 2


In a situation like this I would go for a C# console application using CSOM. The advantage of using CSOM is that you can run the same code from the same machine and update any environment by changing the site url.

Here is an example on how to use CSOM with SharePoint 2010: https://msdn.microsoft.com/en-us/library/ff798388.aspx

Here is a SharePoint 2013 function that I once wrote to remove all the nulls from all the list items with string columns using CSOM. It should work with SharePoint 2010. I am sure that you can improvise a bit.

    private void UpdateNulls()
        using (ClientContext context = new ClientContext(siteUrl))
            List oList = context.Web.Lists.GetByTitle(LISTNAME);
            CamlQuery allItemsQuery = CamlQuery.CreateAllItemsQuery();
            ListItemCollection listItemCollection = oList.GetItems(allItemsQuery);
            ListItemCollectionPosition currentPosition = null;
                allItemsQuery.ListItemCollectionPosition = currentPosition;

                currentPosition = allItemsQuery.ListItemCollectionPosition;

                foreach (ListItem item in listItemCollection)
                    bool nullFound = false;
                    KeyValuePair<string, object>[] keyValuePairs = item.FieldValues.ToArray();
                    for (int i = 0; i < keyValuePairs.Length; i++)
                        if (keyValuePairs[i].Value is string && keyValuePairs[i].Value.Equals("NULL"))
                            item[keyValuePairs[i].Key] = string.Empty;
                            nullFound = true;
                    if (nullFound)
            while (currentPosition != null);

This one fetches all items which is not suitable in your situation but the MSDN link above will help you to filter items using CAML. You will want to fetch items using ParentId and process them.

Hope this helps.



Here are the steps you should follow

  1. Since CAML don't have distinct option, you need to get all documents and then create an Array of distinct Parent Id
  2. Then for each Parent Id, get all documents which has NULL process number

    • Now loop through those documents updating the process number
  • please can you provide the powershell script or camel query function
    – adilahmed
    Commented Apr 1, 2015 at 6:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.