首页 > 解决方案 > Get-AzResourceGroup 返回“在上下文中找不到租户”

问题描述

我刚刚打开 PowerShell 并运行:

> Connect-AzAccount
> Get-AzResourceGroup

并收到此错误。

Get-AzResourceGroup:在上下文中找不到租户。请确保您提供的凭据有权访问 Azure 订阅,然后运行 ​​Connect-AzAccount 登录。

> Get-AzSubscription

警告:无法为租户“Common”获取令牌

Get-AzSubscription:无法向租户进行身份验证。请确保您的帐户有权访问此租户并使用 Connect-AzAccount 登录

我已经有一年没有使用 Azure PowerShell了。我将连接命令给我的 URL 复制粘贴到同一个浏览器中,因为我打开了 Azure 订阅并照常登录。我是 Azure 子系统的唯一管理员和用户。这是我的版本。

> $PSVersionTable.PSVersion

Major  Minor  Patch  PreReleaseLabel BuildLabel
-----  -----  -----  --------------- ----------
7      1      4

我试图重新安装 Azure PowerShell 模块,但更加陌生。

> Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force
Install-Package: C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1:9711
Line |
9711 |  … talledPackages = PackageManagement\Install-Package @PSBoundParameters                                                                                                           |                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Administrator rights are required to install or update. Log on to the computer with an account that has Administrator rights, and then try again, or install by
     | adding "-Scope CurrentUser" to your command. You can also try running the Windows PowerShell session with elevated rights (Run as Administrator).

显然,我以管理员身份运行并且我已经指定了CurrentUser范围。我将放弃并尝试 Azure CLI。

在 GitHub 上提出问题:https ://github.com/Azure/azure-powershell/issues/15842

标签: azure-powershell

解决方案


我认为安装 Azure CLI 解决了它。

自发布以来,我实际上只做过这些事情。

  • 安装了 Google Cloud CLI 和 GCP SDK。
  • 花 10 个小时阅读 GCP 文档,了解一堆东西,因为我很想看看他们的草到底有多绿。
  • 根据 Github 问题上的某人的要求,尝试安装不同的 Az PS 包但失败。
  • 尝试并成功安装了 Microsoft.Graph PS 包,再次作为我的 Github 朋友要求的测试。
  • 通过 MSI 安装了 Azure CLI。
  • 阅读@BhargaviAnnadevara 的评论并尝试了一下,发现一切正常。

推荐阅读