【发布时间】:2019-10-03 16:36:42
【问题描述】:
我正在尝试使用我的公司 O365 帐户连接到我的 Azure AD。当我在 PS shell 中运行命令时,效果很好。但尝试制作 ps1 脚本文件时,ISE 中的命令失败。下面的代码和错误:
代码:
$managedcred = get-storedcredential -Target o365
connect-azuread -credential $managedcred
错误:
Connect-AzureAD:出现一个或多个错误。:AADSTS50126:用户名或密码无效。 跟踪 ID:3bbf3cba-61c3-45c5-a19f-60973b7c2700 相关 ID:14599060-8bb3-4fce-afda-621efc3660ed 时间戳:2019-10-03 16:05:03Z 在行:1 字符:1 + 连接 AzureAD -Credential $managedcred + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AadAuthenticationFailedException + FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
Connect-AzureAD:出现一个或多个错误。 在行:1 字符:1 + 连接 AzureAD -Credential $managedcred + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AggregateException + FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
Connect-AzureAD:AADSTS50126:用户名或密码无效。 跟踪 ID:3bbf3cba-61c3-45c5-a19f-60973b7c2700 相关 ID:14599060-8bb3-4fce-afda-621efc3660ed 时间戳:2019-10-03 16:05:03Z 在行:1 字符:1 + 连接 AzureAD -Credential $managedcred + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AdalServiceException + FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
Connect-AzureAD:响应状态代码不表示成功:400 (BadRequest)。 在行:1 字符:1 + 连接 AzureAD -Credential $managedcred + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], HttpRequestException + FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
Connect-AzureAD : {"error":"invalid_grant","error_description":"AADSTS50126: 用户名或密码无效。\r\n跟踪 ID: 3bbf3cba-61c3-45c5-a19f-60973b7c2700\r\n相关 ID: 14599060-8bb3-4fce-afda-621efc3660ed\r\n时间戳: 2019-10-03 16:05:03Z","error_codes":[50126],"timestamp":"2019-10-03 16:05:03Z","trace_id":"3bbf3cba-61c3-45c5-a19f-60973b7c2700","correlation_id ":"14599060-8bb3-4fce-afda-621efc366 0ed","error_uri":"https://login.microsoftonline.com/error?code=50126"}: 未知错误 在行:1 字符:1 + 连接 AzureAD -Credential $managedcred + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : AuthenticationError: (:) [Connect-AzureAD], AdalException + FullyQualifiedErrorId : Connect-AzureAD,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
Connect-AzureAD:出现一个或多个错误。:AADSTS50126:用户名或密码无效。 跟踪 ID:3bbf3cba-61c3-45c5-a19f-60973b7c2700 相关 ID:14599060-8bb3-4fce-afda-621efc3660ed 时间戳:2019-10-03 16:05:03Z 在行:1 字符:1 + 连接 AzureAD -Credential $managedcred + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Connect-AzureAD], AadAuthenticationFailedException + FullyQualifiedErrorId : Microsoft.Open.Azure.AD.CommonLibrary.AadAuthenticationFailedException,Microsoft.Open.Azure.AD.CommonLibrary.ConnectAzureAD
所以看起来第一个命令工作正常,但连接失败。
【问题讨论】:
-
看起来您用于连接的凭据不正确?你有什么方法可以确认你检索的内容是正确的吗?
-
我不知道如何确保它们被正确拉动。但是,我在 ISE 和 CLI 中使用了完全相同的两个命令。 CLI 工作,ISE 失败
-
更新:现在它在任何一个平台、ISE 或 CLI 中都不起作用
标签: powershell azure-active-directory