首页 > 解决方案 > Connect-MsolService:身份验证错误:意外的身份验证失败

问题描述

我正在尝试使用“应用程序密码”作为身份验证 MFA 方法通过 powershell 脚本连接到 azure AD。

这是我的脚本:

$username = 'user@example.com'
    $Password = ConvertTo-SecureString 'MyPassword' -AsPlainText -Force
    $creds = new-object System.Management.Automation.PSCredential($username, $password)
    Connect-MsolService -Credential $creds

但我得到了这个错误:

Connect-MsolService:身份验证错误:意外的身份验证失败

标签: azurepowershellazure-active-directoryazure-powershellmulti-factor-authentication

解决方案


不能在参数中输入密码,因为用户使用MFA登录,而不是用户名/密码,你应该让它弹出登录框并触发 MFA。

这里有一个类似的问题


推荐阅读