How to globally set the deleted item retention period in Exchange Online?

13,927

Solution 1

I asked Microsoft support, and they told me this can not only be done, but it can even be done by the customer, without requiring any support call.

The global configuration for the deleted items retention period is stored in the Mailbox Plans assigned to users:

PS C:\windows\system32> Get-MailboxPlan | ft Name, RetainDeletedItemsFor

Name                                                          RetainDeletedItemsFor
----                                                          ---------------------
ExchangeOnlineDeskless-200f67ad-971f-4485-8df4-496cb337aaa0   14.00:00:00
ExchangeOnlineEnterprise-7d4dfcb8-b74f-4fbc-b154-008eba3ed7ab 14.00:00:00
ExchangeOnline-6562c5b9-cec6-4d6c-bbed-5cd1551877c7           14.00:00:00

In order to configure it, you can use the Set-MailboxPlan cmdlet:

Get-MailboxPlan | Set-MailboxPlan -RetainDeletedItemsFor "30.00:00:00"

After doing this, the global settings will be changed:

PS C:\windows\system32> Get-MailboxPlan | ft Name, RetainDeletedItemsFor

Name                                                          RetainDeletedItemsFor
----                                                          ---------------------
ExchangeOnlineDeskless-200f67ad-971f-4485-8df4-496cb337aaa0   30.00:00:00
ExchangeOnlineEnterprise-7d4dfcb8-b74f-4fbc-b154-008eba3ed7ab 30.00:00:00
ExchangeOnline-6562c5b9-cec6-4d6c-bbed-5cd1551877c7           30.00:00:00

This will apply the settings to all new users; however, you'll still need to modify it for existing users:

Get-Mailbox | Set-Mailbox -RetainDeletedItemsFor "30.00:00:00"

Solution 2

Further to @massimo's answer, I ran into a problem running:

Get-Mailbox | Set-Mailbox -RetainDeletedItemsFor "30.00:00:00",

with the error:

The operation couldn't be performed because 'username' matches multiple entries.

This appears to occur because the Get-Mailbox cmdlet doesn't pass the mailbox object to the pipeline, but this is a value that Set-Mailbox attempts to match against, and this lookup sometimes fails because it returns more than one mailbox. The solution is to use a unique field, SamAccountName:

Get-Mailbox | % { Set-Mailbox -Identity $_.SamAccountName -RetainDeletedItemsFor "30.00:00:00" }

Share:
13,927

Related videos on Youtube

Massimo
Author by

Massimo

"Against stupidity, the Gods themselves fight in vain." https://www.linkedin.com/in/massimo-pascucci

Updated on September 18, 2022

Comments

  • Massimo
    Massimo over 1 year

    The default retention period for deleted items (those you can recover by using "Recover Deleted Items" in Outlook) is 14 days, but it can be changed; however, this is a per-mailbox setting, and it needs to be changed using PowerShell, because there is no GUI setting for it. It's easy enough to do this for all existing users, but then this process will need to be repeated anytime a new user is created.

    Is there any way to globally set the default deleted item retention period in Exchange Online, so that it's automatically applied to new mailboxes?

    (I'm tagging the question with Exchange-2013 too, since that's what Exchange Online is (currently) based on, and the question also applies to the on-premise edition.)

  • kralyk
    kralyk almost 10 years
    Will it let you set it for more than 90 days? That was the reason I called them and went the route I did. Does it let you set it for like 365 days?
  • Massimo
    Massimo almost 10 years
    I checked... I can't set it to more than 30 days, on any plan. I can't even set it to more than 30 days on a single mailbox, although it actually has an E3 license assigned. This is quite strange.
  • kralyk
    kralyk almost 10 years
    Yeah, probably why when I worked with them last year I ended up going the Litigation Hold route. 30 days just isn't enough for us...especially without paying a 3rd party solution for "Exchange Online Backups"