I am trying to edit a large number of items (>400,000) on a sharepoint list using Powershell and GET-SPWeb. Ideally there would be a way to get only half or a quarter of the items at a time.
The following code worked up to 100.000 items, but throws
The following exception occurred while trying to enumerate the collection: Not enough storage is available to complete this operation (0x8007000e)
when trying to enter the foreach loop.
The server on which I am running this script locally has 64 GB of RAM.
$site = 'http://sharepointserver'
$SiteWebObject = Get-SPWeb $site
$SiteWebObjectList = $SiteWebObject.Lists["List"]
$SiteWebObjectListItems = $SiteWebObjectList.Items
$spQuery = New-Object Microsoft.SharePoint.SPQuery ($SiteWebObjectList["List"])
do {
$listItems = $SiteWebObjectList.GetItems($spQuery)
$spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
foreach ($item in $SiteWebObjectListItems) {
# edit item
}
}
while ($spQuery.ListItemCollectionPosition -ne $null)