Connect-Msolservice: Authentication Error: Unexpected Authentication Failure

I'm trying to connect to azure AD using "App Passwords" as authentication MFA method through powershell script.

this is my script:

$username = '[email protected]'
    $Password = ConvertTo-SecureString 'MyPassword' -AsPlainText -Force
    $creds = new-object System.Management.Automation.PSCredential($username, $password)
    Connect-MsolService -Credential $creds

But I got this error:

Connect-MsolService : Authentication Error: Unexpected authentication failure

1

2 Answers

I had a similar issue. I ran the PowerShell below:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

Connect-MsolService
3

You cannot put the password in the parameter, because the user logs in using MFA, not the username/password, you should let it pop up the login box and trigger MFA.

There is a similar problem here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

James H. Sterling

James H. Sterling

Environmental Science & Climate Journalist

James Sterling reports on renewable energy developments, climate policy, ecological conservation, and green tech innovations around the globe.

Share this article
Twitter Facebook Pinterest