6

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
Mike Wilcox
  • 99
  • 1
  • 1
  • 5

5 Answers5

7

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.

Allen Wu
  • 15,529
  • 1
  • 9
  • 20
  • Note the subscription is an 'Azure Pass Sponsorship' for a class. I added myself as owner of the Azure subscription however powershell Get-AzSubscription does not show the 'Azure pass sponsorship' subscription and the 'Get-AzContext -ListAvailable ' still doesnt show a 'subscription field' Any thoughts ? – Mike Wilcox Jun 17 '20 at 14:54
  • note in powershell if I run connect-azaccount I then login successfully and the return output doesnt show a ' subscription name' ie the subscription name is empty ? – Mike Wilcox Jun 17 '20 at 15:06
  • @MikeWilcox Not familiar with 'Azure Pass Sponsorship'. But it seems that you got it from Microsoft right? In your situation, this sponsorship seems to be not activated in your Azure tenant. You should contact Microsoft or someone who provides the sponsorship to activate it for you first. – Allen Wu Jun 18 '20 at 02:41
  • @MikeWilcox Any updates? If my answer is helpful for you, you can accept it as answer( click on the check mark beside the answer to toggle it from greyed out to filled in.). See https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work. This can be beneficial to other community members. Thank you. – Allen Wu Jun 19 '20 at 08:42
  • The 'azure pass sponsorship' came from Learning Tree. Note, if I use the Power Shell (Get-AzContext -ListAvailable) via the Portal cloud shell the subscription name is returned, however, when I use power shell on my laptop the 'subscription name' is not returned. I hear the cloud shell uses 'older versions' of modules ? Maybe that is my issue ? Or could a powershell module need to be updated on my laptop ? – Mike Wilcox Jun 22 '20 at 16:12
  • That command is CommandNotFoundException. – Aashishkebab Jun 10 '23 at 18:27
5

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.

Uday Kiran
  • 487
  • 2
  • 9
  • 29
  • This guided me in the right direction, thank you. However, to get rid of the 'this.Client.SubscriptionId' error, Reader permissions on the subscription are sufficient. – Dieter Sep 15 '22 at 12:17
  • Agree. Reader permissions are enough. @Dieter – Uday Kiran Sep 15 '22 at 14:52
4

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

kevmaitland
  • 131
  • 1
  • 3
0

The following works

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

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

durces
  • 9
  • 1
0

If you are using Application Object, please try to Add the Application Object in Access Control (IAM) as a member at the Subscription level or Resource Group level or individual service and try again