I've written a PowerShell script to import and read a csv file and then update a corresponding SharePoint 2010 Document Library item with the attributes found in the csv.
Everything works perfectly but I have the added complexity of needing to do this with over a million items. I've tested with 5,000 items and the entire process takes a few hours to complete. At this rate, it'll take over a month to do all 1 million+ items.
Is there a better way to write this script or am I stuck due to the insane number of items? My current script is below. Keep in mind that it is working... just slowly.
$xlCSV=6
$xls='z:\shared\Metadata.xlsx'
$csv='z:\shared\Metadata.csv'
$xl=New-Object -com 'Excel.Application'
$wb=$xl.workbooks.open($xls)
$wb.SaveAs($csv,$xlCSV)
$xl.displayalerts=$False
$SPAssignment = Start-SPAssignment
$SPWeb = Get-SPWeb "http://client.contoso.com" -AssignmentCollection $spAssignment
$SPList = $SPWeb.Lists["Shared Documents"]
foreach($i in Import-CSV 'z:\shared\Metadata.csv')
{
$SPItem = $SPList.Items | Where { $_["Name"] -eq $i."Document Name" }
$SPItem["Metadata1"] = $i."META 1"
$SPItem["Metadata2"] = $i."META 2"
$SPItem["Metadata3"] = $i."META 3"
$SPItem["Metadata4"] = $i."META 4"
$SPItem["Metadata5"] = $i."META 5"
$SPItem["Metadata6"] = $i."META 6"
$SPItem["Metadata7"] = $i."META 7"
$SPItem["Metadata8"] = $i."META 8"
$SPItem.Update()
}
Stop-SPAssignment $SPAssignment
$xl.quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($xl)
$xl = $null
Start-Sleep -s 10
Remove-Item "z:\shared\Metadata.csv" -force