I recently needed to update the Deleted Item Retention period in Office 365 from the default 14 days to the maximum allowed (30 days) for all mailboxes in my environment. Since I was migrating mailboxes to Office 365 at the time, I wrote a script that I could add to my process which would update this setting while it was applying quotas to the mailboxes.
Things were working well, apart from a number of Room mailboxes that had been migrated from Exchange on Premise – every time the script ran, I’d get the following warning on all these mailboxes:
The strange thing is that this was only happening for Rooms that were migrated from Exchange on Premise – any new rooms that were created didn’t have this issue. I decided to compare the mailbox attributes of a room that wasn’t affected by this issue to see what the difference was, and found this culprit:
UseDatabaseRetentionDefaults: True
Turning that setting off allowed me to go back and change the RetainDeletedItemsFor setting to 30 days, like I wanted to:
Set-Mailbox mailboxname -UseDatabaseRetentionDefaults $false
Set-Mailbox mailboxname -RetainDeletedItemsFor 30
In order to fix this for all other rooms affected by this issue, use the following command:
Get-Mailbox -ResultSize Unlimited | where {$_.ResourceType -eq “Room” -and $_.UseDatabaseRetentionDefaults -eq $true} | Set-Mailbox -UseDatabaseRetentionDefaults $false
After that, it was a simple matter of re-running my script – the deleted item retention piece looks like this:
$t = New-TimeSpan -Days 14
$retMailboxes = Get-Mailbox -ResultSize unlimited | Where {($_.Name -notmatch “DiscoverySearch” -and $_.RetainDeletedItemsFor -eq $t)}
foreach ($r in $retMailboxes){
Set-Mailbox -Identity $r -RetainDeletedItemsFor 30
Write-Host “Deleted Item Retention for $($r.Name) successfully updated to 30 days” -ForegroundColor Green
}
Hope this helps someone else scratching their head trying to figure out why they’re unable to change the Deleted Item Retention Period on mailboxes!