在没有用户交互的情况下运行“ Connect-MsolService”,并为Powershell进行Windows身份验证

时间:2019-09-10 12:13:35

标签: c# powershell azure-powershell

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

我希望通过当前登录的Windows服务器凭据进行身份验证并进行身份验证。 在Powershell中有什么可能的方法?

1 个答案:

答案 0 :(得分:0)

您可以尝试以下命令以非交互方式登录,请确保该用户帐户未启用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