@Dez-4361
The answer provided by sharatha can be used as a workaround.
Based on your description, I understand that you want to purge Workflow History list. Here’s PowerShell for you.
Note: The $cutoffDate determines which items to keep. As configured, the cutoff date will be current date - 1days. Any items older than 1days will be removed. You can set $cutoffDate according to your requirement.
$webURL = "your site collection URL"
$cutoffDate = (Get-Date).AddDays(-1)
Add-PSSnapin Microsoft.SharePoint.PowerShell -EA SilentlyContinue
Write-Host "`n- Opening web site $webURL"
$web = Get-SPWeb $webURL -ErrorAction SilentlyContinue
if (!($web)) {
Write-Host -ForegroundColor Red "- Unable to open web site $webURL"
Exit
}
Write-Host "- Opening workflow history list"
$list = $web.lists["Workflow History"]
if (!($list)) {
Write-Host -ForegroundColor Red "- Unable to open Workflow History list"
$web.Dispose()
Exit
}
DO {
$cutoffDateF = "{0:MM/dd/yyyy}" -f $cutoffDate
Write-Host "- Looking for items where 'Date Occurred' <= $cutoffDateF"
Write-Host
$rowlimit = 100
$caml="<OrderBy><FieldRef Name='ID' Ascending='TRUE' /></OrderBy><OrderBy><FieldRef Name='ID' /></OrderBy>"
$camlQuery = New-Object Microsoft.SharePoint.SPQuery
$camlQuery.RowLimit = $rowLimit
$camlQuery.Query = $caml
$items = $list.GetItems($camlQuery)
If (!($items)) {
Write-Host -ForegroundColor Red "- No items to process"
Break
}
$itemTotal = $items.Count
$itemCurrent = 1
$itemsDeleted = 0
Write-Host "- Items to process: $($itemTotal)"
$timeStarted = Get-Date
For ($i=$items.count-1; $i -ge 0; $i--) {
$item = $items[$i]
$itemCurrentF = $itemCurrent.ToString().PadLeft($itemTotal.ToString().Length,"0")
$dateOccurredF = "{0:MM/dd/yyyy}" -f $item["Date Occurred"]
Write-Host "- Processing item $itemCurrentF of $($itemTotal) ... " -NoNewline
If ($item['Date Occurred'] -lt $cutoffDate) {
$item.Delete()
Write-Host "Deleted - $dateOccurredF <= $cutoffDateF"
$itemsDeleted++
}
Else {
Write-Host "Ignored - $dateOccurredF => $cutoffDateF"
}
$itemCurrent++
}
$timeFinished = Get-Date
$timeDuration = ("{0:hh\:mm\:ss}" -f ($timeFinished - $timeStarted))
If ($timeDuration.Length -gt 8) { $timeDuration = $timeDuration.Substring(0,12) }
Else { $timeDuration += ".000" }
$timeTotalSeconds = [Math]::Round(($timeFinished - $timeStarted).TotalSeconds)
$deletedPerSecond = [Math]::Round($itemsDeleted / $timeTotalSeconds)
Write-Host
Write-Host "Batch Started: $timeStarted"
Write-Host "Batch Finished: $timeFinished"
Write-Host "Batch Duration: $timeDuration"
Write-Host
Write-Host "Total Seconds: $timeTotalSeconds"
Write-Host "Items Deleted: $itemsDeleted"
Write-Host "Deleted/Second: $deletedPerSecond"
Write-Host
} UNTIL ($itemsDeleted -le 0)
$web.dispose()
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.