首页 > 解决方案 > 在没有用户交互的情况下运行“Connect-MsolService”并为 Powershell 进行 Windows 身份验证

问题描述

我想在 powershell 上运行命令“Connect-MsolService”但没有用户交互。它应该采用 Windows 身份验证。此外,我无法将密码保存在任何外部文本文件中以进行身份​​验证。

我希望通过当前登录的 Windows 服务器凭据对其进行身份验证并进行身份验证。有没有办法在 Powershell 中做到这一点?

标签: c#powershellazure-powershell

解决方案


您可以尝试以下命令以非交互方式登录,确保用户帐户未启用 MFA。

$azureUsername="user@xxxx.onmicrosoft.com"
$azurePassword = ConvertTo-SecureString "<Password>" -AsPlainText -Force
$psCred = New-Object System.Management.Automation.PSCredential($azureUsername , $azurePassword)
Connect-MsolService -Credential $psCred

推荐阅读