New-AzureRmResourceGroup: ‘this.Client.SubscriptionId’ cannot be null

In this azure tutorial, we will discuss how to fix the errors New-AzureRmResourceGroup: ‘this.Client.SubscriptionId’ cannot be null.

New-AzureRmResourceGroup: ‘this.Client.SubscriptionId’ cannot be null [Solved]

The above error came while trying to execute the below cmdlet to create the Azure web app using PowerShell ISE in Azure.

Login-AzureRmAccount
#Specify the Web app Name and Region
$mywebapp = "MyNewWebApp468"  
$myloc = "Central US"  
$myAppPlan = "MyWebApps"
New-AzureRmResourceGroup -Name mynewupdtrsggroup -Location $myloc
New-AzureRmAppServicePlan -Name $myAppPlan -Location $myloc -ResourceGroupName newresgroup -Tier Free
New-AzureRmWebApp -Name $mywebapp -Location $myloc -AppServicePlan $myAppPlan -ResourceGroupName newresgroup 
New-AzureRmResourceGroup  'this.Client.SubscriptionId' cannot be null.

The complete error message is

New-AzureRmResourceGroup : ‘this.Client.SubscriptionId’ cannot be null.
At line:9 char:1

  • New-AzureRmResourceGroup -Name mynewupdtrsggroup -Location $myloc
  • ~~~~~~~~~~~~~
    • CategoryInfo : CloseError: (:) [New-AzureRmResourceGroup], ValidationException
    • FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceGroupCmdlet

New-AzureRmAppServicePlan : ‘this.Client.SubscriptionId’ cannot be null [Solved]

I also got the error “New-AzureRmAppServicePlan: ‘this.Client.SubscriptionId’ cannot be null”. Which came while trying to execute the below cmdlet to create the Azure web app using PowerShell ISE in Azure.

Login-AzureRmAccount
#Specify the Web app Name and Region
$mywebapp = "MyNewWebApp468"  
$myloc = "Central US"  
$myAppPlan = "MyWebApps"
New-AzureRmResourceGroup -Name mynewupdtrsggroup -Location $myloc
New-AzureRmAppServicePlan -Name $myAppPlan -Location $myloc -ResourceGroupName newresgroup -Tier Free
New-AzureRmWebApp -Name $mywebapp -Location $myloc -AppServicePlan $myAppPlan -ResourceGroupName newresgroup 
New-AzureRmAppServicePlan  'this.Client.SubscriptionId' cannot be null

The complete error message is

New-AzureRmAppServicePlan : ‘this.Client.SubscriptionId’ cannot be null.
At line:7 char:1

  • New-AzureRmAppServicePlan -Name $myAppPlan -Location $myloc -Resource …
  • ~~~~~~~~~~~~~~~~~
    • CategoryInfo : CloseError: (:) [New-AzureRmAppServicePlan], ValidationException
    • FullyQualifiedErrorId : Microsoft.Azure.Commands.WebApps.Cmdlets.AppServicePlans.NewAzureAppServicePlanCmdlet

New-AzureRmWebApp : ‘this.SubscriptionId’ cannot be null [Solved]

I also got the error “New-AzureRmWebApp: ‘this.SubscriptionId’ cannot be null”. Which came while trying to execute the below cmdlet to create the Azure web app using PowerShell ISE in Azure.

Login-AzureRmAccount
#Specify the Web app Name and Region
$mywebapp = "MyNewWebApp468"  
$myloc = "Central US"  
$myAppPlan = "MyWebApps"
New-AzureRmResourceGroup -Name mynewupdtrsggroup -Location $myloc
New-AzureRmAppServicePlan -Name $myAppPlan -Location $myloc -ResourceGroupName newresgroup -Tier Free
New-AzureRmWebApp -Name $mywebapp -Location $myloc -AppServicePlan $myAppPlan -ResourceGroupName newresgroup 
New-AzureRmWebApp 'this.SubscriptionId' cannot be null

The complete error message is

New-AzureRmWebApp : ‘this.SubscriptionId’ cannot be null.
At line:8 char:1

  • New-AzureRmWebApp -Name $mywebapp -Location $myloc -AppServicePlan $m …
  • ~~~~~~~~~~~~~~~~~
    • CategoryInfo : CloseError: (:) [New-AzureRmWebApp], ValidationException
    • FullyQualifiedErrorId : Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps.NewAzureWebAppCmdlet

Solution[Solved]

To fix all the above three issues that are New-AzureRmResourceGroup: ‘this.Client.SubscriptionId’ cannot be null, New-AzureRmAppServicePlan : ‘this.Client.SubscriptionId’ cannot be null, New-AzureRmWebApp : ‘this.SubscriptionId’ cannot be null, we need to add the below cmdlets to the script

Get-AzureRmSubscription
Select-AzureRmSubscription  -SubscriptionId xxxx4300-yyyy-xx18-9c9c-feaa72a5cbd1

To get your subscriptionId, Login to the Azure portal and then search for the Subscription

How to get your subscriptionId in Azure portal

Now click on the search result Subscriptions, Use the below SubscriptionId. In case of multiple subscription choose the correct one.

How to get your subscriptionId in Azure portal

Now the complete script will be

Login-AzureRmAccount
Get-AzureRmSubscription
Select-AzureRmSubscription  -SubscriptionId xxxx4300-yyyy-xx18-9c9c-feaa72a5cbd1
#Specify the Web app Name and Region
$mywebapp = "MyNewWebApp468"  
$myloc = "Central US"  
$myAppPlan = "MyWebApps"
New-AzureRmResourceGroup -Name mynewupdtrsggroup -Location $myloc
New-AzureRmAppServicePlan -Name $myAppPlan -Location $myloc -ResourceGroupName newresgroup -Tier Free
New-AzureRmWebApp -Name $mywebapp -Location $myloc -AppServicePlan $myAppPlan -ResourceGroupName newresgroup 
New-AzureRmWebApp 'this.SubscriptionId' cannot be null how to fix
error: ‘subscriptionid’ cannot be null

Note: Verify your subscription is ASM or ARM. Here in this case your Azure subscription should be ARM.

If you have only ASM subscription then you need to add the ARM subscription.

This will fix all these above three errors.

Error: ‘subscriptionid’ cannot be null

Sometimes, while you are trying to remove any of your existing resources from your tenant, you might get the below error.

Remove-AzureRmResourceGroup : ‘this.Client.SubscriptionId’ cannot be null

Remove-AzureRmResourceGroup : 'this.Client.SubscriptionId' cannot be null.

The complete error message is like below

Remove-AzureRmResourceGroup : ‘this.Client.SubscriptionId’ cannot be null.
At line:1 char:1
+ Remove-AzureRmResourceGroup -name DemoRG
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     + CategoryInfo          : CloseError: (:) [Remove-AzureRmResourceGroup], ValidationException
     + FullyQualifiedErrorId : Microsoft.Azure.Commands.Resources.RemoveAzureResourceGroupCmdlet

Error: ‘subscriptionid’ cannot be null [Solved]

If you receive this error when you try to remove your existing resources from your Tenent, Then you have to check the Azure subscription status.

Now, what you need to do is, You have to check the Azure Subscription status using the below Azure PowerShell cmdlet.

Get-AzureRmContext

Remove-AzureRmResourceGroup : ‘this.Client.SubscriptionId’ cannot be null [Solved]

To fix, this issue you can set the Azure Subscription manually by running the below Azure PowerShell cmdlet

 Select-AzureRmSubscription

The complete script is like below

Login-AzureRmAccount
Get-AzureRmSubscription
Select-AzureRmSubscription  -SubscriptionId xxxx4300-yyyy-xx18-9c9c-feaa72a5cbd1

Make sure to update the SubscriptionId based on yours.

This is how you can able to fix the error Remove-AzureRmResourceGroup : ‘this.Client.SubscriptionId’ cannot be null.

New-AzResourceGroup : ‘this.Client.SubscriptionId’ cannot be null

Some times, while creating the Azure Resource Group using the New-AzResourceGroup Azure PowerShell cmdlet, you might get the below error

New-AzResourceGroup : ‘this.Client.SubscriptionId’ cannot be null

After running the below PowerShell script, I got the error

New-AzResourceGroup -Name Demo1RG -Location 'westus'

The error I got was New-AzResourceGroup : ‘this.Client.SubscriptionId’ cannot be null.

New-AzResourceGroup : ‘this.Client.SubscriptionId’ cannot be null [Solved]

To fix the error, You need to set the Azure Subscription for creating any Azure resources without the Azure subscription.

You can select the list of Azure Subscriptions using the Get-AzSubscription Azure PowerShell cmdlet.

Azure Error - This.Client.SubscriptionId' cannot be null
Azure Error – This.Client.SubscriptionId’ cannot be null

The next step is to set the Azure Subscription using the below PowerShell cmdlet

Select-AzSubscription {subscription id}
Select-AzSubscription -SubscriptionId xxxx4300-yyyy-xx18-9c9c-feaa72a5cbd1

Make sure to replace the Azure SubscriptionId with yours.

This is how you can able to fix the error New-AzResourceGroup : ‘this.Client.SubscriptionId’ cannot be null.

Get-AzResourceGroup : ‘this.Client.SubscriptionId’ cannot be null

You might get the error Get-AzResourceGroup: ‘this.Client.SubscriptionId’ cannot be null while executing the Azure PowerShell cmdlet Get-AzResourceGroup.

Get-AzResourceGroup

After executing the above Azure PowerShell cmdlet, you might have got the error Get-AzResourceGroup : ‘this.Client.SubscriptionId’ cannot be null

Get-AzResourceGroup : ‘this.Client.SubscriptionId’ cannot be null [Solved]

To fix the error,

The most important thing is to check if you have the proper permission for the Azure subscription or if you have created any Service Principal if that has proper permission for your Azure subscription.

This is mostly the permission issue, you need at least the Contributor access.

This is how to fix the error Get-AzResourceGroup : ‘this.Client.SubscriptionId’ cannot be null.

Set-azcontext : please provide a valid tenant or a valid subscription

You might get the error Set-azcontext : please provide a valid tenant or a valid subscription while executing the Azure PowerShell cmdlet Set-azcontext.

Set-azcontext

The complete error message is as below

Set-AzContext : Please provide a valid tenant or a valid subscription.
At line:6 char:1
+ Set-AzContext -SubscriptionId xxxx4300-yyyy-xx18-9c9c-feaa72a5cbd1

Now, let’s see how to fix the error Set-azcontext : please provide a valid tenant or a valid subscription

Set-azcontext: please provide a valid tenant or a valid subscription [Solved]

To fix the error Set-azcontext : please provide a valid tenant or a valid subscription, you can follow the below steps.

  • The first step is to close the current PowerShell session or you can also use Clear-AzContext PowerShell cmdlet.
  • Now, you can use the below Azure PowerShell command in this way
Connect-AzAccount -Tenant xxxxx -Subscription xxxxx

Or, you can use the below steps

  • Use the below Azure PowerShell cmdlet to get the list of contexts 
Get-AzContext -ListAvailable
  • You can choose the context using the below Azure PowerShell cmdlet
Select-AzContext -Name #############
  • Now, You can use the script in the below format.
Select-AzContext -name ((Get-AzContext -ListAvailable).Name -match $MySubscriptionId)[0]

In this way you can able to fix the error Set-azcontext: please provide a valid tenant or a valid subscription.

Set-azcontext

Check out the details on set-azcontext now.

Get-azurermsubscription

This is an excellent Azure PowerShell cmdlet to get the subscription details i.e subscription ID, subscription name, and home tenant that the current account can access.

Syntax:

The syntax of the Get-azurermsubscription is as below

Get-AzureRmSubscription
 [-SubscriptionId <String>]
 [-TenantId <String>]
 [-AsJob]
   [-DefaultProfile <IAzureContextContainer>]
 [<CommonParameters>]

If we will consider some of the examples here

Example: Retrieve all the subscriptions in all tenants

You can use the below Azure PowerShell cmdlet to get all the subscriptions in all tenants

PS C:\WINDOWS\system32> Get-AzureRmSubscription
Get-azurermsubscription PowerShell cmdlet

Example 2: How to get all subscriptions for a specific tenant

You can use the below Azure PowerShell cmdlet to retrieve all the subscriptions for a specific tenant.

PS C:\WINDOWS\system32> Get-AzureRmSubscription -TenantId "xxxx-xxxx-xxxx-xxxx"
How to get all subscriptions for a specific tenant

Get-azsubscription

You can check out the details on get-azsubscription now.

Connect-azaccount

You can check out the details on Connect-azaccount now.

Select-azsubscription

The Azure PowerShell cmdlet Select-AzureSubscription is an excellent Azure PowerShell cmdlet that can help you to change the current and default Azure subscriptions.

You may like following Azure tutorials:

In this Azure tutorial, we discussed how to fix the below three errors, 

  • New-AzureRmResourceGroup: ‘this.Client.SubscriptionId’ cannot be null
  • New-AzureRmAppServicePlan : ‘this.Client.SubscriptionId’ cannot be null
  •  New-AzureRmWebApp : ‘this.SubscriptionId’ cannot be null
  • Error: ‘subscriptionid’ cannot be null
  • Remove-AzureRmResourceGroup : ‘this.Client.SubscriptionId’ cannot be null
  • New-AzResourceGroup : ‘this.Client.SubscriptionId’ cannot be null
  • Get-AzResourceGroup : ‘this.Client.SubscriptionId’ cannot be null
  • Set-azcontext : please provide a valid tenant or a valid subscription
  • Set-azcontext
  • Get-azurermsubscription
  • Get-azsubscription
  • Connect-azaccount
  • Select-azsubscription