'this.Client.SubscriptionId' cannot be null

Viewed 11840

We noticed that our Azure Subscription field is empty eg:

Get-AzContext -ListAvailable 

Name                                     Account             SubscriptionName    Environment         TenantId
----                                     -------             ----------------    -----------         --------
kk89gan-db99-41c8-95c4-d43adfdfaf34ad ... mymy@outlook.zzz ...                     AzureCloud          674ce2a1-d4sd1da..

so when I try to run on ps command, I receive an error:

New-AzResourceGroup -Name az1rg -Location 'eastus'
New-AzResourceGroup : 'this.Client.SubscriptionId' cannot be null.
At line:1 char:1
4 Answers

If you don't set an Azure subscription, you won't be allowed to create any Azure resources without the subscription.

You need use Get-AzSubscription to list all the available subscriptions.

Then set the subscription by using Select-AzSubscription {subscription id}.

Now you could create Azure resources.

I notice that your account seems to be a guest user right?

If so, you should assign the guest user as an administrator of a subscription at first. Then the guest user can see the subscription in Powershell.

Add your System Managed Identity as Contributor role in Subscription level.

enter image description here

Add Contributor role on subscription level.

enter image description here

Correct me if I am wrong. Thank You.

The following works

  1. Use Get-AzSubscription to list all the available subscriptions.

  2. Set the subscription by using Select-AzSubscription {subscription id}.

This error also occurs if you are using a Managed Identity to authenticate, but the Automation Account (or Functional App) does not have a Role assigned. Assigning a Role (presumably) "homes" this identity in Subscription and populates this property automatically during authentication.

Issue reported in 2019: https://github.com/Azure/Azure-Functions/issues/1285

Related