azure - 无法使用 powershell 向 azure 进行身份验证

标签 azure powershell authentication scripting azure-active-directory

我们有一个 azure 的租户。 我们开了一个新的租户,并将我们的用户传递给新租户,然后将我们的用户作为访客添加到旧租户中。 通过意味着我们从第一个租户中删除了用户,然后将域迁移到新租户,并在新租户中创建了具有相同属性的用户。

从那时起,每次我们尝试使用 powershell 和推荐的 Connect-azaccount -TenantId 连接到 azure 时,我们都会收到以下错误:

Unable to acquire token for tenant '***' with error 'SharedTokenCacheCredential authentication unavailable. No account matching the specified username: *** tenantId: *** was found in the cache.'

有人知道如何解决这个问题吗?

谢谢

我们已经尝试了网上找到的所有方法。 我们尝试clear-azcontext,从我们的机器中删除证书,删除powershell并重新安装等等...

最佳答案

Unable to acquire token for tenant xxx with error SharedTokenCacheCredential authentication unavailable. No account matching the specified username: xxx tenantId: xxx was found in the cache

如果用户不在您尝试登录的租户中,通常会发生此错误。

要详细检查错误,您可以尝试如下调试:

$DebugPreference = "Continue"
Connect-AzAccount -TenantID XXXX

enter image description here

根据调试详细信息,您可以检查正在连接的用户是哪个租户或任何用户详细信息。

尝试连接订阅 ID,如下所示:

Connect-AzAccount -Subscription SubscriptionID -TenantId TenantID

enter image description here

检查用户是否启用了 MFA 并尝试使用全局管理员帐户进行连接。并且可能是该帐户仍然缓存在本地计算机中的情况,因此请尝试在另一台计算机上是否可以正常工作。

您还可以使用设备身份验证,如下所示:

Connect-AzAccount -Tenant TenantID -UseDeviceAuthentication

打开浏览器并输入代码:

enter image description here

确保安装 Az 模块,如下所示:

首先清除缓存并尝试通过设置执行策略进行安装

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Install-Module Az
Import-Module Az
Update-Module -Name Az

enter image description here

检查租户中的用户帐户是否具有订阅所需的权限。

尝试在 PowerShell 中选择上下文:

Get-AzContext -ListAvailable
Select-AzContext -Name Name

enter image description here

或者您可以通过包含 TenantID 来设置 SubscriptionID 的上下文:

Set-AzContext -Subscription $subscription -Tenant $tenantId | Out-null

enter image description here

如果问题仍然存在,可能是迁移域时出现一些环境问题。

关于azure - 无法使用 powershell 向 azure 进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74890620/

相关文章:

authentication - 401 使用 HttpBuilder (Groovy) 未经授权访问 Github API

linux - 从一个系统无密码登录多台 linux 机器的 Shell 脚本

c# - 将 SSO OpenId/Azure AD 身份验证添加到现有 Web 表单应用程序

sql-server - 从 Azure Synapse Analytics Spark 池连接到 Azure SQL 数据库

python - 如何使用python向eventhub发送多条消息

arrays - 在 PowerShell 中调整字节数组图像的大小

azure - Spring Boot 2.0 使用 spring-cloud 和 azure-spring-boot 启动需要很长时间

Ansible 中的 Powershell 复制项目

powershell - 如何在 PowerShell 中为读取主机配置超时

java - 使用 PKCS11 token (智能卡)进行客户端身份验证