IMAP Migration to Office 365 with PowerShell
In this article
This guide walks you through migrating mailboxes from any IMAP-enabled email system to Microsoft 365 (Office 365) using PowerShell. The process automates what would otherwise be a manual, mailbox-by-mailbox import, saving time and reducing errors. Before you begin, you need: a Microsoft 365 tenant with an active Exchange Online license, the Exchange Online Management module installed, and the credentials for both your source IMAP server and the target Microsoft 365 tenant.
What You'll Need
- Microsoft 365 tenant with Exchange Online licenses assigned to the target mailboxes.
- PowerShell 5.1 or later (Windows) or PowerShell 7 (cross-platform).
- Exchange Online Management V2 module installed (
Install-Module -Name ExchangeOnlineManagement). - Source IMAP server address, port (usually 993 for SSL), and credentials for each source mailbox.
- Target Microsoft 365 admin credentials with the Mailbox Import Export role (Exchange admin role).
- List of source mailboxes and their corresponding target Microsoft 365 user principal names (UPNs).
Step-by-Step
- Install and connect to Exchange Online PowerShell. Open PowerShell as administrator. Run
Install-Module -Name ExchangeOnlineManagement -Scope CurrentUserif not already installed. Then connect:Connect-ExchangeOnline -UserPrincipalName admin@yourdomain.com– sign in with your admin credentials. - Verify target mailboxes exist. Run
Get-Mailbox -ResultSize Unlimited | Select DisplayName, UserPrincipalNameto confirm the mailboxes you’re migrating to are present and licensed. - Create a CSV file with migration data. Create a CSV with columns:
SourceEmail,SourcePassword,TargetUPN. Each row maps a source IMAP mailbox to a target Microsoft 365 mailbox. Save asmigration.csvin a secure location. - Create the migration endpoint. Run:
New-MigrationEndpoint -IMAP -Name "IMAPEndpoint" -RemoteServer imap.yourprovider.com -Port 993 -Security SSL
Replaceimap.yourprovider.comwith your actual IMAP server address. - Create the migration batch. Run:
$batch = New-MigrationBatch -Name "IMAPMigration" -SourceEndpoint "IMAPEndpoint" -CSVData (Get-Content -Path "C:\path\migration.csv" -Encoding Byte) -TargetDeliveryDomain yourdomain.com
This creates the batch but doesn’t start it yet. - Start the migration batch. Run
Start-MigrationBatch -Identity $batch.Identity. The migration will begin synchronizing folders, emails, contacts, and calendar items from the source IMAP server to Microsoft 365. - Monitor the migration. Run
Get-MigrationBatch -Identity "IMAPMigration" | Get-MigrationUser | Select Identity, Status, ItemsSynced, ItemsSkippedto track progress. Wait until all users show statusSynced. - Complete the migration. Once all users are synced, run
Complete-MigrationBatch -Identity "IMAPMigration". This finalizes the migration and stops further syncs. - Verify the migrated data. Log into a few test mailboxes via Outlook on the web to confirm emails, folders, and contacts are present. You can also run
Get-MailboxStatistics -Identity user@domain.com | Select MailboxSize, Itemsto see item counts.
Common Mistakes
- Using the wrong IMAP port or security type. Most IMAP servers use 993 with SSL, but some use 143 with STARTTLS. Check your provider’s documentation.
- Not assigning licenses before migration. If the target mailbox lacks an Exchange Online license, the migration will fail or the mailbox won’t be created.
- Incorrect CSV formatting. The CSV must have headers exactly as specified, and passwords should be plain text (which is why the file must be secured).
- Forgetting to include all source folders. By default, IMAP migration syncs all folders, but if you have custom folders, ensure they are not excluded by any folder filter.
- Starting the batch before creating the endpoint. The migration batch references the endpoint; it must exist first.
Tips
- Run a small pilot migration with a few test mailboxes first to validate the process and catch issues early.
- Use a dedicated admin account for the migration, and consider using a service principal or managed identity if available for better security.
- Schedule the migration during off-peak hours to minimize impact on users.
- Keep the CSV file encrypted or delete it after migration – it contains plaintext passwords.
- If you have a large number of mailboxes, split them into multiple batches (e.g., 50–100 per batch) to avoid throttling.
- After migration, set up a cutover date and inform users to reconfigure their email clients to connect to Microsoft 365.
Troubleshooting
- Migration fails with “Connection to source server failed.” Check the IMAP server address, port, and SSL settings. Test with a simple IMAP client like Thunderbird to ensure credentials work.
- Items are skipped during sync. Common reasons: messages larger than the mailbox size limit, corrupted items, or folder name conflicts. Review the migration report (available via
Get-MigrationUserStatistics) for specific error codes. - Migration batch stays in “Syncing” state for too long. Check if the source server is throttling connections. Increase the
Concurrencyparameter on the migration endpoint (e.g.,New-MigrationEndpoint -Concurrency 50) or split the batch. - Mailbox not found error. Ensure the target UPN in the CSV matches an existing licensed mailbox. Use
Get-Mailbox -Identity UPNto verify. - PowerShell module fails to load. Run
Import-Module ExchangeOnlineManagementand ensure you have the latest version. If on Windows, run PowerShell as administrator. - Migration completes but some folders are missing. IMAP doesn’t support all folder types (e.g., Journal, Notes). These will not be migrated. Also, check if the source server has special folder names that need mapping.
Frequently Asked Questions
Can I migrate from Gmail or Yahoo using this method?
Yes, as long as you enable IMAP access in those services and use an app-specific password if two-factor authentication is enabled.
Will my email rules and filters be migrated?
No. IMAP migration only transfers emails, contacts, calendar items, and folder structure. Server-side rules do not migrate; users will need to recreate them in Outlook or Outlook on the web.
How long does the migration take?
It depends on the number of mailboxes, the volume of data, and the source server’s speed. Typically, a mailbox with 2–3 GB of data can take a few hours, but large migrations can take days.
Can I run the migration without PowerShell?
Yes, the Exchange admin center has a built-in IMAP migration wizard, but PowerShell gives you more control and is easier to automate for many mailboxes.
What happens if a user changes their password during migration?
If the source IMAP password changes, the migration will fail for that mailbox. You’ll need to update the CSV and re-run the batch.
Do I need to keep the source server running after migration?
Yes, until you complete the migration and verify all data. After completion, you can decommission the source server.