Exchange Online (MS 365) - Auto Expanding Online Archives

Exchange Online (MS 365) - Auto Expanding Online Archives
Photo by Ula Kuźma / Unsplash


Managing storage in Microsoft 365 mailboxes can be a challenge, especially for users with high retention needs. Auto-expanding archives are a fantastic feature that lets you take storage worries off your plate by dynamically adding more capacity when needed.

Here’s a straightforward guide on enabling this feature, the licensing you’ll need, and a PowerShell script you can use to get it done.

What Are Auto-Expanding Archives?

If you’re not familiar, auto-expanding archives allow Microsoft 365 mailboxes to grow beyond their initial archive limit. Once the primary archive hits its quota, additional storage is automatically allocated. This makes them a solid option for organizations that deal with significant amounts of email and data retention requirements.

Licensing Requirements

To use auto-expanding archives, you’ll need one of these licenses:

  • Microsoft 365 Business Premium
  • Microsoft 365 E3 or E5
  • Office 365 E3 or E5
  • Exchange Online Plan 2
Note: Basic plans like Microsoft 365 Business Standard or Exchange Online Plan 1 don’t support auto-expanding archives.

Preparing Your Environment

Before enabling auto-expanding archives, make sure:

  1. You have sufficient permissions (Global Admin or Exchange Admin roles).
  2. PowerShell 7 is installed. If you’re still on Windows PowerShell 5.1, it’s worth upgrading to take advantage of better performance and features. Here’s a guide to installing PowerShell 7.
  3. The Exchange Online Management PowerShell module is installed. If it’s not, the script will handle that for you.

The PowerShell Script

Here’s a script to enable auto-expanding archives. It’s built to handle everything from checking for modules to verifying archive status.

# Step 1: Set the execution policy to allow signed scripts
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force

# Step 2: Check for the Exchange Online Management module and install if necessary
if (!(Get-Module -ListAvailable -Name ExchangeOnlineManagement)) {
    Write-Host "Exchange Online Management module not found. Installing..."
    Install-Module -Name ExchangeOnlineManagement -Force
}

# Import the module
Import-Module ExchangeOnlineManagement

# Step 3: Connect to Exchange Online
Write-Host "Connecting to Exchange Online. You may be prompted for authentication."
Connect-ExchangeOnline -UserPrincipalName "admin@yourdomain.com"

# Step 4: Option to enable archiving for all users without an archive
Write-Host "Do you want to enable archiving for all users without an existing archive? (Y/N)"
$response = Read-Host
if ($response -eq "Y" -or $response -eq "y") {
    Write-Host "Enabling archiving for mailboxes without an archive..."
    Get-Mailbox -Filter {ArchiveGuid -Eq "00000000-0000-0000-0000-000000000000" -AND RecipientTypeDetails -Eq "UserMailbox"} | Enable-Mailbox -Archive
    Write-Host "Archiving enabled for all applicable users."
}

# Step 5: Option to enable auto-expanding archive for a specific mailbox
Write-Host "Do you want to enable auto-expanding archives for a specific mailbox? (Y/N)"
$response = Read-Host
if ($response -eq "Y" -or $response -eq "y") {
    $mailbox = Read-Host "Enter the email address of the mailbox"
    Write-Host "Enabling auto-expanding archive for $mailbox..."
    Enable-Mailbox $mailbox -AutoExpandingArchive

    # Verify the auto-expanding archive status
    Write-Host "Verifying auto-expanding archive status for $mailbox..."
    Get-Mailbox $mailbox | FL AutoExpandingArchiveEnabled
    Write-Host "Auto-expanding archive enabled for $mailbox."
}

# Optional: Check archive usage statistics for a mailbox
Write-Host "Do you want to check archive usage statistics for a mailbox? (Y/N)"
$response = Read-Host
if ($response -eq "Y" -or $response -eq "y") {
    $identity = Read-Host "Enter the email address of the mailbox to check"
    Write-Host "Checking archive usage statistics for $identity..."
    Get-MailboxStatistics -Identity $identity -Archive | Select DisplayName, TotalItemSize, ItemCount
    Get-Mailbox -Identity $identity | Select ArchiveStatus, ArchiveDatabase
    Write-Host "Statistics retrieved for $identity."
}

Write-Host "Script execution completed."

These changes should reflect almost immediately on Exchange Online,

Read more