migrate to App Only and Managed Identity!
In many tenants, scheduled Exchange scripts still authenticate using a service account: password stored as an encrypted file on the server, `Connect-ExchangeOnline -Credential $cred`, done. This has worked for years because the parameter uses the ROPC (Resource Owner Password Credentials) flow under the hood.
The script sends the username and password directly to Entra ID and receives a token in return. There is no interactive step involved, so neither MFA nor Conditional Access policies can intervene. A service account with Exchange admin rights that bypasses all policies is the exact scenario attackers are looking for.
Microsoft is therefore removing the parameter from the module. Today, many environments still have scripts with stored credentials distributed across Task Schedulers, jump servers, and Azure Automation accounts. After the change, every unattended script will authenticate as an app using a certificate or via a Managed Identity, every human will log in interactively with MFA, and service accounts with passwords will disappear.
What’s changing and by when
According to Message Center entry MC1248389, versions of the ExchangeOnlineManagement module released from December 2026 onwards will no longer include the -Credential parameter. This affects Connect-ExchangeOnline and Connect-IPPSSession. The original plan was to implement this change in July 2026. Microsoft has not provided a reason for the six-month delay, though admins had strongly criticized the short lead time in comments on the initial announcement. For now, the change is client-side only: older module versions will continue to accept the parameter. Microsoft has announced a server-side deprecation of the sign-in flow but has not specified a date.
Concurrently, MC1483974 is active. Starting March 31, 2027, Microsoft will enforce stricter sign-in requirements for Exchange Online PowerShell, with the rollout expected to complete by the end of April 2027. Module versions below 3.10.1 may then fail during interactive sign-ins, particularly under PowerShell 7 with WAM disabled. As of November 8, 2026, 3.10.1 (released July 24, 2026) is the current stable version, while 3.11.1-Preview1 has been available in the PowerShell Gallery since October 22.
Both dates create a loophole: Version 3.10.1 meets MC1483974 and still includes -Credential. A pinned module buys you time. However, it’s only a temporary bridge, as the server-side deprecation is coming, and you’ll be locked out of any later module versions with security fixes. There’s also a dependency that’s often overlooked: Since version 3.10.0, the module requires at least PowerShell 7.6 under PowerShell 7. Windows PowerShell 5.1 is unaffected.
Step by step
Find affected scripts
Before you register a single app, you need a list. Searching directly for the parameter catches most cases:
$Pfade = 'C:\Scripts', '\\fs01\automation$'
Get-ChildItem -Path $Pfade -Include *.ps1, *.psm1 -Recurse -ErrorAction SilentlyContinue |
Select-String -Pattern 'Connect-(ExchangeOnline|IPPSSession)[^\r\n]*-Credential' |
Select-Object Path, LineNumber, Line |
Export-Csv -Path .\credential-inventar.csv -NoTypeInformation -Encoding UTF8Scripts that pass their connection parameters via splatting slip through this filter because `-Credential` is not on the same line. Therefore, run a second search with the pattern `Credential\s*=` and manually check the hits. The same applies to runbooks in Azure Automation: export them once and run them through the same search.
In the second pass, you check which module versions are installed on each server.
Get-Module ExchangeOnlineManagement -ListAvailable | Select-Object Name, Version, ModuleBaseWhen multiple versions are available, PowerShell loads the highest one by default unless explicitly specified. A script that runs on 3.9.2 today could therefore break after an update in December without any code changes.
2: Set the login method per script
The decision depends on where and for whom the script runs. If a human is in front of it, they authenticate interactively using Connect-ExchangeOnline -UserPrincipalName. Since module version 3.7.0, this defaults to WAM, so MFA and Conditional Access apply without additional configuration.
If the script runs unattended in Azure, Managed Identity is the better approach because there is no secret that can expire or leak. According to the cmdlet reference, it supports Runbooks in Azure Automation, Azure Functions, virtual machines, and VM Scale Sets.
If the script runs unattended on its own server, such as in Task Scheduler, stick with app-only authentication using a certificate. If the script uses eDiscovery cmdlets or the cmdlets for Microsoft 365 Groups, jump straight to step 5, as neither of the two methods will work there.
3: Set up app-only with certificate
The app registration is the identity under which your script will operate in the future. Create it as a single-tenant app. Under API permissions, add the application permission Exchange.ManageAsApp—for Exchange Online from the "Office 365 Exchange Online" API, and for Security & Compliance PowerShell from "Microsoft Exchange Online Protection". If a script requires both environments, the app receives both permissions. Afterward, grant admin consent and revoke consent for the default User.Read Graph permission, as the app does not need it.
Next, you generate the certificate. A self-signed certificate is acceptable, as is one from your own PKI. The key point is the key provider: Exchange Online does not accept CNG certificates, only those with a CSP provider. The parameter `-KeySpec KeyExchange` ensures this:
$Zert = New-SelfSignedCertificate -DnsName 'exo-automation.contoso.de' -CertStoreLocation 'Cert:\CurrentUser\My' -NotAfter (Get-Date).AddYears(1) -KeySpec KeyExchange
$Zert | Export-Certificate -FilePath .\exo-automation.cerGenerate the certificate in the context of the account under which the scheduled task runs, as authentication via `-CertificateThumbprint` looks for it in the executing account's memory and only works on Windows. Upload the public part, i.e., the `.cer` file, in the app registration. Only export the private key if the script is to run on a second server, and never store the password in plain text in the script. Microsoft explicitly states in the documentation that a certificate password stored using `ConvertTo-SecureString` negates the security benefit.

Now the app needs permissions in Exchange. The quick way is an Entra role like Exchange Recipient Administrator or Global Reader. The clean way is a dedicated Exchange role group containing only the roles the script requires. A reporting script with Exchange Administrator could delete mailboxes in an emergency, but with the View-Only Recipients role, it cannot. To do this, you create a service principal in Exchange Online that points to the enterprise app:
Connect-MgGraph -Scopes 'Application.Read.All' -NoWelcome
$App = Get-MgServicePrincipal -Filter "DisplayName eq 'EXO Automation'"
Connect-ExchangeOnline -UserPrincipalName admin@contoso.de
New-ServicePrincipal -AppId $App.AppId -ObjectId $App.Id -DisplayName 'SP EXO Automation'
$SP = Get-ServicePrincipal -Identity 'SP EXO Automation'
Add-RoleGroupMember -Identity 'Automation Empfaenger' -Member $SP.IdentityFirst, create the role group "Automation Recipients" using New-RoleGroup with the appropriate roles.



In the script itself, you then replace the old login:
Connect-ExchangeOnline -CertificateThumbprint '<Thumbprint>' -AppId '<AppId>' -Organization 'contoso.onmicrosoft.com' -ShowBanner:$falseFor -Organization, you must specify the primary .onmicrosoft.com domain, not a verified customer domain. Under Linux or in containers, -CertificateThumbprint is omitted; instead, pass the certificate as an X509Certificate2 object via -Certificate.
4: Managed Identity for Azure Automation Runbooks
To enable Runbooks, activate the system-assigned Managed Identity of the Automation account and import ExchangeOnlineManagement as a module.
The permission Exchange.ManageAsApp cannot be assigned to a Managed Identity via the portal; you must grant it using Graph PowerShell. The App ID and App Role ID are the same in every tenant, only the object ID of the resource service principal differs:
Connect-MgGraph -Scopes 'AppRoleAssignment.ReadWrite.All', 'Application.Read.All' -NoWelcome
$MI_ID = '<Objekt-ID der Managed Identity>'
$AppRoleID = 'dc50a0fb-09a3-484d-be87-e023b12c6440'
$ResourceID = (Get-MgServicePrincipal -Filter "AppId eq '00000002-0000-0ff1-ce00-000000000000'").Id
New-MgServicePrincipalAppRoleAssignment -ServicePrincipalId $MI_ID -PrincipalId $MI_ID -AppRoleId $AppRoleID -ResourceId $ResourceIDThen assign an Entra role to the Managed Identity, for example using New-MgRoleManagementDirectoryRoleAssignment, or add it to a custom role group as shown above with New-ServicePrincipal. In the runbook, a single line is sufficient:
Connect-ExchangeOnline -ManagedIdentity -Organization 'contoso.onmicrosoft.com'Ensure the runtime: If you import version 3.10.0 or newer into a PowerShell 7 environment, the runbook's Runtime Environment must be set to PowerShell 7.6, as the module requires PowerShell 7.6 from this version onward. Runtime 7.4 will lose support on November 10, 2026, anyway.
5: Cmdlets that cannot use app-only authentication
Two sets of cmdlets do not work with either certificates or managed identities. They are not mentioned in the announcement itself, only in the comments below it.
The first group are the cmdlets for Microsoft 365 Groups: New-UnifiedGroup, Remove-UnifiedGroup, Add-UnifiedGroupLinks, and Remove-UnifiedGroupLinks. Microsoft Graph offers full replacements for these. You create groups with New-MgGroup, add members with New-MgGroupMemberByRef, and remove them with Remove-MgGroupMemberByRef. This requires migration effort, but it’s not a blocker.
The second group is tougher: the Purview eDiscovery cmdlets in Security & Compliance PowerShell, including New-ComplianceSearch, Start-ComplianceSearch, New-ComplianceSearchAction, Get-ComplianceSearchAction, and New-CaseHoldPolicy. Microsoft explicitly lists them as unsupported in app-only mode.
In response to a question in the Exchange Team blog about how admins should automate these cmdlets without the -Credential parameter, the answer was that SCC cmdlets, lacking app-only support, are not intended for automation now or in the future, as they were not designed for it. For existing automation, the documentation mentions a transitional approach: version 3.10.1, the -EnableSearchOnlySession switch when connecting, along with a service principal and eDiscovery roles. However, this configuration is also not officially supported.
The intended approach uses the eDiscovery API in Microsoft Graph. The app is granted the application permission eDiscovery.ReadWrite.All and additional rights in Purview. To do this, you create a service principal in Security & Compliance PowerShell and add it to the eDiscoveryManager role group:
Connect-IPPSSession -UserPrincipalName admin@contoso.de
New-ServicePrincipal -AppId '<AppId>' -ObjectId '<Objekt-ID der Enterprise-App>' -DisplayName 'eDiscovery Automation'
Add-RoleGroupMember -Identity 'eDiscoveryManager' -Member '<Objekt-ID der Enterprise-App>'
Add-eDiscoveryCaseAdmin -User '<Objekt-ID der Enterprise-App>'The classic cleanup using New-ComplianceSearchAction -Purge is replaced by the purgeData endpoint. It accepts application permissions but is only available in the Graph beta version and deletes a maximum of 100 items per location per run:
Connect-MgGraph -ClientId '<AppId>' -TenantId 'contoso.onmicrosoft.com' -CertificateThumbprint '<Thumbprint>' -NoWelcome
$Body = @{ purgeType = 'recoverable'; purgeAreas = 'mailboxes' }
Invoke-MgGraphRequest -Method POST -Uri "https://graph.microsoft.com/beta/security/cases/ediscoveryCases/$CaseId/searches/$SearchId/purgeData" -Body $BodyThe API responds with 202 and provides the address in the Location header where you can query the progress. A beta endpoint in a deletion process is a risk you must consciously accept or reject. If you don’t want that, you’ll have to perform cleanups interactively with MFA in the future. That’s how Microsoft intends it, according to the blog response.
Conclusion
The deprecation of -Credential is long overdue. A service account that logs in as an Exchange admin using a password and bypasses every Conditional Access policy was already unacceptable years ago. The comments under the initial announcement show just how many production processes still rely on this. Those who switch now get more than just a working script: Only when no admin account logs in via ROPC can you enforce MFA without exceptions for Exchange Online PowerShell.
Criticism of Microsoft remains justified. There is no supported app-only method for eDiscovery purges in Security & Compliance PowerShell, and the Graph alternative is still in beta for purge operations. Anyone who needs to remove phishing emails from mailboxes on a schedule today must either integrate a beta API into their deletion process or revert to manual intervention. This is a gap Microsoft must close before the server-side shutdown takes effect.
Three factors determine whether the migration will succeed in operations.
- First: certificates expire. A self-signed certificate with a one-year validity will break your script after twelve months if no one monitors the expiration. Log the expiry date in your monitoring or use Managed Identity wherever the script can be moved to Azure.
- Second: Pin the module to 3.10.1 only as a temporary measure and with a fixed end date.
- Third: Disable and delete the old service accounts as soon as the last dependency has been migrated, and rotate the passwords beforehand. A service account that exists only 'just in case' is the next entry point.
💬 Comments
0 commentsBe the first to start the discussion with a helpful comment.
Leave a comment
Comments are reviewed briefly before they are published — factual, respectful and to the point is just right here.