Fix 401 Unauthorized Error in Office 365 Migration
In this article
When migrating to Office 365, a 401 Unauthorized error typically means the authentication credentials or permissions are incorrect, or the token used to access resources has expired or lacks the necessary scopes. This guide walks you through resolving this error step by step, covering common causes like stale credentials, misconfigured permissions, and incorrect API settings.
What You'll Need
- Global admin or Exchange admin credentials for the source and target tenants (if cross-tenant).
- Access to the Microsoft 365 admin center and Azure AD (now Microsoft Entra ID).
- The migration tool or script you're using (e.g., Exchange Admin Center, PowerShell, third-party tool).
- Network access to the endpoints involved (e.g., autodiscover, outlook.office365.com).
- Basic familiarity with PowerShell if using scripts.
Step-by-Step
- Identify the exact context of the 401 error. Note where it occurs: during autodiscover, mailbox sync, or API call. This helps narrow down the cause.
- Verify your credentials. Ensure the admin account you're using has the required licenses (Exchange Online) and the correct role (Global Admin or Exchange Admin). Test by logging into the Microsoft 365 admin center with the same account.
- Check if the account is enabled for basic authentication. In many tenants, basic auth is disabled by default. If your migration tool uses basic auth (username/password), enable it temporarily for the migration account in Azure AD (Security > Authentication methods > Basic authentication) or use modern auth (OAuth) if supported.
- Re-authenticate and refresh tokens. If you're using PowerShell or a third-party tool, clear cached credentials. For PowerShell, use
Connect-ExchangeOnlineand ensure you sign in with the correct account. For a tool, log out and back in. - Review API permissions in Azure AD. If your migration uses an app registration (e.g., for Graph API), verify the app has the necessary delegated or application permissions (like Mail.ReadWrite, MailboxSettings.ReadWrite). Go to Azure AD > App registrations > your app > API permissions, and ensure they're granted and consented by an admin.
- Check for conditional access policies. These can block sign-ins. Go to Azure AD > Conditional Access, and see if any policy applies to the migration account or app. Temporarily exclude the account or app to test.
- Ensure the source and target endpoints are correct. For cross-tenant migrations, verify the source tenant's autodiscover URL is reachable and the target tenant is correct. Use
Test-MigrationServerAvailabilityin Exchange Online PowerShell. - Reset the migration account password. If the password was recently changed or expired, reset it and update it in the migration tool.
- Check for MFA (multi-factor authentication). If MFA is enabled on the migration account, the tool may not support it. Create an app password or use a service account with MFA disabled (if allowed by your security policies).
- Review firewall or proxy settings. Ensure that your network allows outbound connections to Microsoft endpoints. A proxy that strips authentication headers can cause 401 errors.
- Retry after a short wait. Sometimes 401 errors are transient due to token expiration or service hiccups. Wait 5-10 minutes and retry.
Common Mistakes
- Using a user account that lacks the required admin role (e.g., using a regular user instead of Global Admin).
- Forgetting to enable basic auth for the migration account when using legacy tools.
- Not granting admin consent for app permissions in Azure AD.
- Using stale credentials that were changed after the migration was configured.
- Ignoring conditional access policies that block the migration.
- Mixing up source and target tenant credentials in cross-tenant scenarios.
Tips
- Use a dedicated migration account with just the needed permissions (e.g., Exchange Admin) to reduce risk.
- Prefer modern authentication (OAuth) over basic auth whenever possible, as it's more secure and reliable.
- Keep a log of the exact error message and timestamp; this helps when contacting support.
- Test with a single mailbox first before running a full migration.
- If using PowerShell, use the latest version of the Exchange Online Management module.
Troubleshooting
If the 401 error persists, try these additional steps:
- Check the Microsoft 365 service health for any ongoing incident related to Exchange Online or Azure AD.
- Use the Microsoft Remote Connectivity Analyzer to test autodiscover and connectivity for the migration account.
- Enable verbose logging in your migration tool to see the full HTTP response headers; the
WWW-Authenticateheader can hint at the auth scheme required. - Try a different migration tool (e.g., Exchange Admin Center instead of PowerShell) to isolate whether the issue is tool-specific.
- Check if the source mailbox is on-premises and if the on-premises server requires specific permissions (e.g., full access to the mailbox).
- Contact Microsoft Support if the error occurs across multiple accounts and tools, as it may indicate a tenant-level issue.
Frequently Asked Questions
Why do I get a 401 error even with correct admin credentials?
Often it's because the account lacks the specific role (e.g., Exchange Admin) or because MFA is blocking the sign-in. Also, conditional access policies can deny access even with valid credentials.
Can I fix a 401 error by just re-entering my password?
Sometimes, if the password was changed or expired. But if the issue is permissions or MFA, re-entering won't help. Always verify the account's roles and MFA status.
Does disabling basic auth affect my migration?
Yes, if your migration tool uses basic auth. You can enable it temporarily for the migration account, but consider using modern auth for security.
How do I check if my app has the right permissions in Azure AD?
Go to Azure AD > App registrations > your app > API permissions. Look for the required permissions (e.g., Mail.ReadWrite) and ensure they are granted with admin consent.
What if the error occurs only for some mailboxes?
That could indicate a specific mailbox issue, such as a corrupted item or a size limit. Check the migration log for the exact mailbox and try migrating that mailbox separately.
Can a firewall cause a 401 error?
Yes, if a proxy or firewall strips authentication headers or blocks required endpoints, you can get 401 errors. Ensure your network allows connections to Microsoft's URLs (e.g., *.outlook.com).