【问题标题】:Get-AzResourceGroup : 'this.Client.SubscriptionId' cannot be nullGet-AzResourceGroup:“this.Client.SubscriptionId”不能为空
【发布时间】:2019-04-05 14:54:14
【问题描述】:

Azure 和 Powershell 有点问题。我只是在检查资源组是否存在,并且一直遇到此错误。之后的下一步是创建资源组(如果它不存在),但这也会引发相同的错误。希望有人能够提出一些解决方法或修复建议。

请注意,我可以访问订阅,我可以看到它们并成功设置默认订阅,如下面的脚本所示。

返回完整错误

'this.Client.SubscriptionId' cannot be null.
At **********************\envir\create-env.ps1:21 char:1
+ Get-AzResourceGroup -Name $resourceGroup -ErrorVariable $doesNotExist ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzResourceGroup], ValidationException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.GetAzureResourceGroupCmdlet

我刚刚安装了 Az 模块,版本详情如下。

Version    Name                                Repository
-------    ----                                ----------
1.6.0      Az                                  PSGallery

我只是在运行一个非常简单的脚本(如下),我认为这可能与未设置默认订阅有关,但设置没有任何区别。

$passwd = ConvertTo-SecureString $servicePrincipalKey -AsPlainText -Force
$pscredential = New-Object 
System.Management.Automation.PSCredential($servicePrincipalUserName, $passwd)
Connect-AzAccount -ServicePrincipal -Credential $pscredential -TenantId $tenantId
Select-AzureSubscription -Default -SubscriptionName $subscriptioName
Get-AzResourceGroup -Name $resourceGroup -ErrorVariable $doesNotExist 

然后我得到上面列出的错误。

【问题讨论】:

  • 您可能没有任何订阅权限?
  • 感谢您的回复,但通过使用 $subs = Get-AzureSubscription 进行身份验证后,我实际上可以看到我的订阅。
  • 你有 azurerm 模块的剩余部分吗?我建议你删除那些。如果您跳过选择该特定订阅而只选择get-azresourcegroup,该怎么办?
  • 我已经运行了 Uninstall-AzureRm,因为它警告了冲突。我也重新启动以防万一。如果我注释掉 Connect-AzAccount,我仍然会收到同样的错误。我还清除了 Azure 配置文件并从头开始重试。

标签: azure powershell azure-devops


【解决方案1】:

我发现了问题,我创建的服务主体没有足够的权限访问订阅,正如@4c74356b41 所建议的那样,我最终赋予它贡献者的角色并解决了问题。

【讨论】:

  • 嗨@PatrickLu-MSFT,您不能将自己的答案标记为问题的答案,其他人必须这样做。亲切的问候。
猜你喜欢
  • 2020-10-06
  • 2017-06-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-01
  • 2020-08-18
  • 1970-01-01
  • 2021-03-05
  • 2018-01-23
相关资源
最近更新 更多