How to delete older version of sharepoint list items using Powershell in Sharepoint 2010/2013/2016?
Hello SharePointers,
Below is the Powershell script to delete the older version of SharePoint list item. This script will delete the older version which lasts more than 12 months or after.
$SPweb = Get-SPWeb “http://mysite/goodness”
$limit = (Get-Date).AddMonths(-12)
$SPlist = $SPweb.Lists[“Doc1”]
foreach ($SPitem in $SPlist.Items)
{
$VersionsCount= $SPItem.Versions.count
for($v=$VersionsCount-1;$v -ge 0;$v–)
{
if($SPitem.Versions[$v].IsCurrentVersion){
}
else{
if($limit -gt $SPitem.Versions[$v].Created)
{
$SPitem.Versions[$v].delete();
}
}
}
}
Happy SharePointing 🙂