0 XP

Signing in with Connect-ExchangeOnline

Interactive sign-in

Connect-ExchangeOnline -UserPrincipalName admin@contoso.com starts interactive modern authentication, with or without MFA, and pre-fills the username. This is the everyday admin connection.

Two older routes fail with MFA: -Credential does not work with MFA accounts, and -InlineCredential does not work with MFA and is PowerShell 7 only.

No browser on the machine

-Device runs the device code flow: you open https://microsoft.com/devicelogin on another device and enter the code. It needs module 2.0.4 or later and works only in PowerShell 7. In Windows PowerShell 5.1 it fails, so switch shells.

The PowerShell 7-only pair to remember is -Device and -InlineCredential.

App-only certificate auth

Unattended scripts use an app registration and a certificate:

  • -AppId with the application ID;
  • one certificate parameter: -CertificateThumbprint, -Certificate (an X509Certificate2 object, for example from Azure Key Vault), or -CertificateFilePath with -CertificatePassword;
  • -Organization with the tenant's primary .onmicrosoft.com domain, such as contoso.onmicrosoft.com.

Example: Connect-ExchangeOnline -AppId (id) -CertificateThumbprint (thumbprint) -Organization "contoso.onmicrosoft.com".

The traps

  • -CertificateThumbprint works only on Windows. A script moved to a Linux container must switch to -Certificate or -CertificateFilePath with -CertificatePassword.
  • The three certificate parameters are mutually exclusive. Passing two "to be safe" is an error.
  • -Organization does not take the custom domain (contoso.com), an object ID, or an admin UPN.
  • -Device is interactive, so it never suits an unattended job.

Picking the method

  • A person at a desk with a browser: -UserPrincipalName, which handles MFA.
  • A person on a machine with no browser: -Device, from PowerShell 7.
  • A scheduled script on Windows: -AppId, -CertificateThumbprint and -Organization.
  • A scheduled script on Linux or macOS: -AppId, -Certificate or -CertificateFilePath with -CertificatePassword, and -Organization.

All of these are PowerShell-only; the EAC has no setting for how a shell signs in.

Knowledge check

6 questions on what you just read. Each answer shows the full explanation and its source.

Loading…