
Admin accounts should be protected with MFA, and that includes PowerShell. With the ExchangeOnlineManagement module you sign in to Exchange Online with MFA, just as in the browser. This article shows how, and how to run scripts without a sign-in window.
Interactive sign-in with MFA
- Install the module if you haven't yet. Read install the Exchange Online PowerShell module.
- Type: Connect-ExchangeOnline -UserPrincipalName admin@contoso.com
- Sign in in the window and confirm with the Authenticator app.

Without a browser on the device
Working on a server or in a session without a browser? Use Connect-ExchangeOnline -Device. You get a code to enter on another device at microsoft.com/devicelogin.
For unattended scripts
For scheduled tasks, use certificate-based authentication (app-only):
- Create an app registration in Entra ID and add a certificate.
- Give the app the API permission Exchange.ManageAsApp and assign an Exchange role, such as Exchange Administrator.
- Connect with Connect-ExchangeOnline -AppId <id> -CertificateThumbprint <thumbprint> -Organization contoso.onmicrosoft.com.
In Azure Automation or Azure Functions you can use a managed identity (-ManagedIdentity). Never store passwords in a script.
Troubleshooting
- Error about Basic Authentication? You're using an old module or the old New-PSSession method. Update the module.
- No permissions? Check that your account has an Exchange admin role. Read admin roles in Microsoft 365.
- MFA not set up yet? Read enable MFA.
Nederlandstalige versie: Aanmelden op Exchange Online PowerShell met MFA of een certificaat
Related articles
▸Install the Exchange Online PowerShell module (ExchangeOnlineManagement)Install the ExchangeOnlineManagement module, learn what changed since V2 and connect to Exchange Online with…
▸Install and configure Exchange Server as a hybrid serverInstall Exchange Server SE, run the Hybrid Configuration Wizard and enable Exchange hybrid deployment in…
▸Install and use the Microsoft Teams PowerShell moduleInstall the MicrosoftTeams module, connect with MFA and manage teams, channels, members and policies with…
▸Basic authentication in Exchange Online is permanently disabledBasic authentication in Exchange Online no longer works. See what stopped, how to find legacy sign-ins and…
▸Delete a Microsoft 365 group or distribution group with PowerShellDelete Microsoft 365 groups and distribution groups with Exchange Online PowerShell or Microsoft Graph, and…