0

I have a PowerShell script that updates documents in a library. The script takes input values, then updates specific documents based on the values.

If I run a single instance of the script, it works just fine. If I run two instances of the script at the same time, randomly I will receive the error below.

Script1 inputs:
$internalName = "CarColor"
$entityID = "Black"

Script2 inputs:
$internalName = "CarColor"
$entityID = "White"

With the two scripts running, a couple hundred updates are made and a couple errors are thrown. Restore the content db and start the process over. The scripts won't throw errors on the same documents again, but errors will be thrown on other documents.

Error message

System.Management.Automation.ExtendedTypeSystemException: The following exception was thrown when trying to enumerate the collection: "". ---> Microsoft.SharePoint.SPException ---> System.Runtime.InteropServices.COMException (0x80131904): 0x80131904 at Microsoft.SharePoint.Library.SPRequestInternalClass.GetListItemDataWithCallback2(IListItemSqlClient pSqlClient, String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pPagingPrevCallback, ISPDataCallback pFilterLinkCallback, ISPDataCallback pSchemaCallback, ISPDataCallback pRowCountCallback, Boolean& pbMaximalView) at Microsoft.SharePoint.Library.SPRequest.GetListItemDataWithCallback2(IListItemSqlClient pSqlClient, String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pPagingPrevCallback, ISPDataCallback pFilterLinkCallback, ISPDataCallback pSchemaCallback, ISPDataCallback pRowCountCallback, Boolean& pbMaximalView) --- End of inner exception stack trace --- at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) at Microsoft.SharePoint.Library.SPRequest.GetListItemDataWithCallback2(IListItemSqlClient pSqlClient, String bstrUrl, String bstrListName, String bstrViewName, String bstrViewXml, SAFEARRAYFLAGS fSafeArrayFlags, ISP2DSafeArrayWriter pSACallback, ISPDataCallback pPagingCallback, ISPDataCallback pPagingPrevCallback, ISPDataCallback pFilterLinkCallback, ISPDataCallback pSchemaCallback, ISPDataCallback pRowCountCallback, Boolean& pbMaximalView) at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData() at Microsoft.SharePoint.SPListItemCollection.GetEnumerator() at System.Management.Automation.LanguagePrimitives.GetEnumerator(Object obj) --- End of inner exception stack trace --- at System.Management.Automation.LanguagePrimitives.GetEnumerator(Object obj) at System.Management.Automation.foreachStatementNode.Execute(Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context) at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)

Example of CAML query:

    $spQuery = New-Object Microsoft.SharePoint.SPQuery
    $spQuery.ViewAttributes = "Scope='Recursive'"

    if ($internalNamesFound.Length -eq 2)
    {
        $camlQuery = '<Where><Or>'

        foreach ($internalName in $internalNamesFound)
        {
            $camlQuery += '<Eq><FieldRef Name="' + $internalName + '" /><Value Type="Text">' + $entityID + '</Value></Eq>'
        }

        $camlQuery += '</Or></Where>'
    }
    else
    {
        $camlQuery = '<Where><Eq><FieldRef Name="' + $internalNamesFound[0] + '" /><Value Type="Text">' + $entityID + '</Value></Eq></Where>'
    }

    $spQuery.Query = $camlQuery
    $getItems = $list.GetItems($spQuery)
2
  • You getting a save conflict error
    – Nikhil J
    Sep 23, 2016 at 14:56
  • @NikhilJ any suggestions on avoiding the save conflict? ... Each PowerShell instance is updating a unique set of documents. Sep 23, 2016 at 15:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.