‘this.client.subscriptionid’ cannot be null.

This Azure tutorial will discuss how to fix the error ‘this.Client.SubscriptionId’ cannot be null which I got while working with multiple PowerShell commands.

‘this.client.subscriptionid’ cannot be null.

The above error came while executing 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 
'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

I also got the error “New-AzureRmAppServicePlan: ‘this.Client.SubscriptionId’ cannot be null”. This 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 
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

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

I also got the error “New-AzureRmWebApp: ‘this.SubscriptionId’ cannot be null”. This 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 
'this.client.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

‘this.client.subscriptionid’ cannot be null. [Solved]

To fix all the above three issues, 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

you are using the set-azurermvmsourceimage command with the -version parameter. you wish to ensure that you get the most current image. which value should you use with the -version parameter?

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

'this.client.subscriptionid' cannot be null

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