MFA Security Issues

Fix Microsoft 365 PowerShell Automation After Conditional Access MFA

Camila MilosovichCamila Milosovich Nov 18, 2026 870 views

Question details

The user needs a supported authentication method for PowerShell scripts after MFA enforcement stopped their automation.

Fix Microsoft 365 PowerShell Automation After Conditional Access MFA
Product
Microsoft 365, Microsoft Entra Conditional Access, and PowerShell
Device & OS
not provided
Scenario
PowerShell scripts need to access Microsoft 365 after a baseline MFA policy is enabled.
Observed behavior
The scripts stopped working, and the user cannot find app passwords or the usual additional-security-verification options under Conditional Access MFA.
Before you start

Identify the PowerShell module and connection command used by each affected script, and determine whether it runs interactively or unattended. Ask a Microsoft Entra administrator to check the applicable MFA policy and sign-in logs.

Solution 1Recommended

Use modern authentication for PowerShell automation

Use a certificate or managed identity for unattended scripts, or device-code sign-in when a user can complete MFA.

Conditional Access MFA does not generally make app passwords a solution for modern authentication automation. Available authentication methods and permissions depend on the PowerShell module and the Microsoft 365 service.

For unattended automation, use an application identity with a certificate or a managed identity where the module and hosting environment support it. Grant only the required application permissions and obtain administrator consent where required.

1
Check the module

Open the script and identify its Connect command. Consult that module's documentation to confirm whether it supports certificate-based authentication, managed identity, or device-code sign-in.

2
Configure an unattended identity

In the Microsoft Entra admin center, use Identity > Applications > App registrations to register an application and configure its certificate and required API permissions. Alternatively, enable a managed identity on a supported Azure resource and grant it the required permissions.

3
Update the connection command

For Microsoft Graph PowerShell, use Connect-MgGraph -ClientId <app-id> -TenantId <tenant-id> -CertificateThumbprint <thumbprint> for certificate authentication, or Connect-MgGraph -Identity from a supported Azure environment with a configured managed identity.

4
Use device code when interactive

For an interactive Microsoft Graph session, run Connect-MgGraph -Scopes <required-scopes> -UseDeviceAuthentication, then follow the displayed instructions to sign in and complete any required MFA.

5
Test the script

Run the updated script in its intended environment and verify that its API calls succeed. If access is denied, review the identity's permissions, administrator consent, and applicable tenant policies.

Use modern authentication for PowerShell automation
Choose the method for the module: The Connect-MgGraph examples apply to Microsoft Graph PowerShell. Other modules may use different commands or support different authentication methods.
Free Microsoft Office alternative

Work with Office files using WPS Office

WPS Office is a free, lightweight alternative with a familiar interface and support for common Microsoft Office formats, making it easy to move everyday document work. It does not replace Microsoft Entra authentication or fix PowerShell automation.

Edit documents, spreadsheets, and presentations in a familiar interfaceOpen and save common Microsoft Office formats, including DOCX, XLSX, and PPTXUse a free, lightweight suite for everyday Office file tasksKeep document editing separate from Microsoft 365 PowerShell authentication troubleshooting
microsoft office alternative - wps office

Frequently Asked Questions

Can I use an app password to bypass Conditional Access MFA for my script?

App passwords are not generally a solution for modern authentication automation under Conditional Access. Check the module's supported authentication methods and use a certificate, managed identity, or interactive sign-in as appropriate.

Which authentication method should an unattended script use?

Use certificate-based application authentication or a managed identity if the module and hosting environment support it. Configure the identity and required permissions in Microsoft Entra, and grant administrator consent where required.

Can device-code sign-in run without a user?

No. Device-code sign-in requires a user to follow the displayed sign-in instructions and complete any required MFA. For unattended jobs, consider a supported application identity or managed identity instead.

Where can I see why a PowerShell sign-in failed?

In the Microsoft Entra admin center, open Identity > Monitoring & health > Sign-in logs. Find the relevant sign-in and inspect its failure details and Conditional Access results where available.