PowerShell script to enable litigation hold for all user mailboxes in Exchange

The following PowerShell script will enable litigation hold for all user mailboxes in your environment. The script will work for Exchange 2010 and 2013, both On-Premise or Online.

# First you need to be connected to the Exchange PowerShell.

$pagesize = 100; # The number of mailboxes per loop
$inc = 0; # Start increment value

# Continue until all mailboxes are litigation hold enabled
do {
    Write-Output "Getting mailboxes"
    # Get UserMailboxes that does not have litigation hold enabled
    $mailboxes = Get-Mailbox -Filter {LitigationHoldEnabled -eq $false -and RecipientTypeDetails -eq "UserMailbox"} -ResultSize $pagesize -WarningAction SilentlyContinue
    if($mailboxes) { Write-Output ("Current mailbox count: {0}" -f ($inc += $mailboxes.Count))}
    # Enable litigation hold
    $mailboxes | Set-Mailbox -LitigationHoldEnabled $true -WarningAction SilentlyContinue
} while($mailboxes);

Write-Output "Done"

It is possible to add additional filtering by editing the filter for the Get-Mailbox cmdlet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s