Connect-AzureAD:parsing_wstrust_response_failed:解析 WS-Trust 响应失败

Connect-AzureAD : parsing_wstrust_response_failed: Parsing WS-Trust response failed

每次我 运行 我的脚本通过 Powershell 连接到 Azure Ad 时,我都会收到以下错误

Connect-AzureAD : One or more errors occurred.: parsing_wstrust_response_failed: Parsing WS-Trust response failed
At C:\Azure-AD\Azure-Connect.ps1:10 char:1
+ Connect-AzureAD -TenantId $TenantId -credential $MyCredential
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : AuthenticationError: (:) [Connect-AzureAD], AadAuthenticationFailedException
    + FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD

下面是我创建的脚本

$TenantId = ""
$SecFile = "C:\Azure-AD\Password.txt"
$SecUser = "C:\Azure-AD\UserName.txt"
$MyCredential = New-Object -TypeName System.Management.Automation.PSCredential  -ArgumentList $SecUser,
 (Get-Content $SecFile | ConvertTo-SecureString)

Connect-AzureAD -TenantId $TenantId-credential $MyCredential

我正在使用以下行来生成加密我的密码

(Get-Credential).Password | ConvertFrom-SecureString | Out-File "C:\AzureAD\Password.txt"

有关如何修复错误并通过 Powershell 连接到 Azure Ad 的任何解决方案

我已经在我的环境中进行了测试。

请使用以下脚本:

$tenantID = ""
$secfile = "C:\Azure-AD\Password.txt";
$secuser = "C:\Azure-AD\UserName.txt";
$username = Get-Content $secuser;
$password = Get-Content $secfile |  ConvertTo-SecureString -AsPlainText -Force;
$MyCredential = New-Object Management.Automation.PSCredential ($username, $password);
Connect-AzureAD -TenantId $tenantID -credential $MyCredential