SharePoint + Powershell: Remove Hold, Record Declaration on All Documents in a Library
In order to delete a Records Library or Records Center, all holds and records in a library must be removed and the Holds and Processing timer job must be run. If this criteria is not met, the "Delete this Document Library" will not be an option in the library settings.
Here is how you can do this programmatically. Note that I did not include the deletion of documents or the document library itself. $siteURL = $args[0] $libraryName= $args[1]
$site = Get-SPSite $siteURL $web = $site.RootWeb $library = $web.Lists[$libraryName] $records = $library.Items[0]
# First, remove all holds from all items in the Library $holdsList = $web.Lists["Holds"] $holds = $holdsList.Items[0] [Microsoft.Office.RecordsManagement.Holds.Hold]::RemoveHold($records,$holds,"Holds have been removed.")
# Next, undeclare all items as records. Ps. BulkUndeclareItemsAsRecords is useless. foreach ($record in $records) { [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::UndeclareItemAsRecord($item) }
Start-SPTimerJob HoldProcessing
$web.Dispose() $site.Dispose() Thanks to anavijai for the sample Hold removing code.