Last week I had a question to remove a document library with items that where records.
Then you have an option to remove the record status of every document by hand, this is ok for a few items but in this case there were a few thousand items and only some of them had the status Record.
With some searching on the internet I found a code snippet to remove the record status of a document.

[Microsoft.Office.RecordsManagement.RecordsRepository.Records]::UndeclareItemAsRecord($item)

But not all items where a record so I had to check first if the item was a record, this can be done with the following line

$IsRecord = [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::IsRecord($item)

In this library there where too much items to get all of them at once I created a recursive function to query each folder and undeclare the items in it.

Function GetFolder($folder)
{
$query = new-object -TypeName “Microsoft.SharePoint.SPQuery”
$query.Folder = $folder
$items = $list.GetItems($query)
foreach($item in $items)
{
$IsRecord = [Microsoft.Office.RecordsManagement.RecordsRepository.Records]::IsRecord($item)
    if ($IsRecord -eq $true)
{
[Microsoft.Office.RecordsManagement.RecordsRepository.Records]::UndeclareItemAsRecord($item)
    }
}
foreach($fol in $folder.SubFolders)
{
GetFolder($fol)
}
}

When the script is done, a timerjob has to run to finalize the process.
This timerjob is called “Hold Processing and Reporting”

Leave a Reply

%d bloggers like this: