Share via


Exchange : Enable Mailbox Auditing, Archiving and Legal Hold using PowerShell

The below script will help us to enable mailbox auditing, archiving and legal hold on Exchange.

Please, save the script below as .PS1 file and then run.

Import-Module ExchangeOnlineManagement
 
Connect-ExchangeOnline -Credential $UserCredential -ShowProgress $truE
 
Get-Mailbox -ResultSize Unlimited -Filter{RecipientTypeDetails -eq "UserMailbox"} | Set-Mailbox -AuditEnabled $true
 
Get-Mailbox -Filter {ArchiveStatus -Eq "None" -AND RecipientTypeDetails -eq "UserMailbox"} | Enable-Mailbox -Archive
 
Get-Mailbox -ResultSize Unlimited -Filter "RecipientTypeDetails -eq 'UserMailbox'"  | Set-Mailbox -LitigationHoldEnabled $true


Write-Host "DONE RUNNING SCRIPT FOR ENABLING MAILBOX AUDITING, ARCHIVING AND LEGAL HOLD, PLEASE CHECK ERRORS"
 
Read-Host -Prompt "Press Enter to exit"