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

时间:2021-01-21 07:07:56

标签: azure powershell azure-active-directory azure-powershell multi-factor-authentication

我正在尝试通过 powershell 脚本使用“应用密码”作为身份验证 MFA 方法连接到 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:身份验证错误:身份验证意外失败

1 个答案:

答案 0 :(得分:0)

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

这里有一个 similar problem