Archiving in Microsoft 365 (Exchange Online) is typically managed by retention policies, but you can manually trigger archiving using PowerShell. This script will force archiving for a user’s mailbox by running the Managed Folder Assistant (MFA).
Prerequisites
Before running the script, ensure you have:
✅ Exchange Online PowerShell module installed (ExchangeOnlineManagement
).
✅ Global Administrator or Exchange Administrator privileges.
✅ Archiving enabled for the mailbox.
Step 1: Connect to Exchange Online
We need to authenticate and establish a session with Exchange Online.
# Import Exchange Online Management module
Import-Module ExchangeOnlineManagement
# Connect to Exchange Online
Connect-ExchangeOnline -UserPrincipalName admin@yourtenant.com
🔹 Explanation:
Import-Module ExchangeOnlineManagement
ensures the necessary module is available.Connect-ExchangeOnline
prompts for admin credentials and establishes a session.
Step 2: Run the Managed Folder Assistant (MFA) to Trigger Archiving
The Managed Folder Assistant (MFA) processes mailboxes according to retention policies and forces archiving.
# Run Managed Folder Assistant for a specific user
Start-ManagedFolderAssistant -Identity user@yourtenant.com
🔹 Explanation:
Start-ManagedFolderAssistant
forces an immediate archive process based on the retention policy.- Replace
user@yourtenant.com
with the mailbox you want to process.
Step 3: Force Archiving for All Mailboxes
If you want to apply archiving to all mailboxes, use the following command:
# Run Managed Folder Assistant for all mailboxes
Get-Mailbox -ResultSize Unlimited | Start-ManagedFolderAssistant
🔹 Explanation:
Get-Mailbox -ResultSize Unlimited
fetches all mailboxes.- The result is piped into
Start-ManagedFolderAssistant
, forcing archiving for each mailbox.
Step 4: Verify Archive Processing Status
To check if archiving is working, use:
# Check archive mailbox status
Get-MailboxStatistics -Identity user@yourtenant.com | Select DisplayName, TotalItemSize, ItemCount
🔹 Explanation:
- This command returns mailbox size and item count, helping confirm if archiving has reduced mailbox size.
Step 5: Disconnect the Session
After execution, disconnect the Exchange session:
# Disconnect Exchange Online session
Disconnect-ExchangeOnline -Confirm:$false
🔹 Explanation:
- This safely closes the session to prevent unnecessary resource usage.
Conclusion
This script ensures that archiving is triggered immediately, rather than waiting for Microsoft’s automated schedule. It is useful when mailboxes are growing too fast and need immediate cleanup. 🚀