Get-AzResourceGroup:'this.Client.SubscriptionId'不能为空

问题描述 投票:0回答:1

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 

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

azure powershell azure-devops
1个回答
1
投票

我发现了问题,我创建的服务主管没有按照@ 4c74356b41的建议获得足够的订阅权限,我最终给了它一个贡献者的角色,并解决了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.