Enable Litigation Hold for all Mailboxes in Office 365
Written on December 17, 2015

There’s no built-in feature at this time to enable litigation hold for all mailboxes in Exchange Online, but some organisations have this as a requirement. Here’s a script that can be run ad-hoc to enable litigation hold for all mailboxes. When prompted, enter your Exchange Online credentials.

# Connect to Exchange Online
$exo = New-PSSession -ConfigurationName Microsoft.Exchange `
-ConnectionUri https://ps.outlook.com/powershell-liveid `
-Authentication Basic `
-AllowRedirection `
-Credential $(Get-credential)

Import-PSSession $exo

# Get all mailboxes that do not have litigation hold enabled
$mailboxes = Get-Mailbox -ResultSize Unlimited -Filter {RecipientTypeDetails -eq "UserMailbox"} | 
Where {$_.LitigationHoldEnabled -ne $true}

# Enable litigation hold
$mailboxes | Set-Mailbox -LitigationHoldEnabled $true 

Remove-PSSession $exo 

Comments/questions

There's no commenting functionality here. If you'd like to comment, please either mention me (@[email protected]) on Mastodon or email me. I don't have any logging or analytics running on this website, so if you found something useful or interesting it would mean a lot to hear from you.