Fix Microsoft 365 PowerShell Automation After Conditional Access MFA
Question details
The user needs a supported authentication method for PowerShell scripts after MFA enforcement stopped their automation.

- 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.
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.
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.
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.
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.
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.
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.
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.

Investigate the MFA policy and sign-in failure
Use sign-in details to determine which policy or authentication requirement is blocking the script.
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.

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.




