Hey SharePoint Ninjas,
I have a SharePoint 2010 list that has approx 9000 items. Now, each item has 4000+ versions (crazy I know)
I cannot rely on normal foreach loop in powershell to delete it. It is taking way too longer to delete the versions. I tried changing the versioning settings to "No versions" but to no success. The versions are still present there and consuming storage.
Any suggestions on how to tackle this?
Here is the code I am using -
$SPWeb = Get-SPWeb "http://thatsiteagain.sharepoint.com"
$myList = $SPWeb.Lists["My Crazy List"]
$itemColl = $myList.Items
foreach ($myItem in $itemColl)
{
$versionsToDelete = $myItem.Versions
$verCount = $versionsToDelete.Count
for ($i = $verCount-1; $i -ge 0 ; $i--)
{
if (!$versionsToDelete[$i].IsCurrentVersion)
{
$versionsToDelete[$i].Delete()
}
}
}