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

In this azure tutorial, we will discuss how to fix the error, Get-AzVm: ‘this.Client.SubscriptionId’ cannot be null while executing the PowerShell cmdlet to retrieve the Azure Virtual Machine Details using the PowerShell ISE.

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

Recently, I was trying to execute the PowerShell cmdlet to retrieve the Azure Virtual machine details. I was using the below PowerShell cmdlet

PS C:\WINDOWS\system32> Get-AzVm -Name mynewvm

When I tried executing the above PowerShell cmdlet, I got the error Get-AzVm : ‘this.Client.SubscriptionId’ cannot be null. You can see the error below.

Get-AzVm : 'this.Client.SubscriptionId' cannot be null
get-azvm

The exact error message was like below

Get-AzVm : ‘this.Client.SubscriptionId’ cannot be null.
At line:1 char:1

  • Get-AzVm -Name mynewvm
  • ~~~~~~
    • CategoryInfo : CloseError: (:) [Get-AzVM], ValidationException
    • FullyQualifiedErrorId : Microsoft.Azure.Commands.Compute.GetAzureVMCommand

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

To fix this error, you need to follow the below steps

The first thing is you need to get your Azure Subscription ID and Tenant ID. We need to use these two IDs in our PowerShell Script. To get these IDs, follow the below steps

Login to the Azure Portal(https://portal.azure.com/)

Once you logged in to the Azure Portal, click on the portal Menu as highlighted below. then, from the left navigation click on the Cost Management + Billing. On the Overview tab, you can able to see the Subscription ID as highlighted below. Now copy this ID and keep it with you.

'this.Client.SubscriptionId' cannot be null
‘this.client.subscriptionid’ cannot be null.

Now the next is we need to copy the Tenant ID, To get the Tenant ID, click on the portal Menu as highlighted below. then, from the left navigation click on the Azure Active Directory. Now you can able to see below the Tenant ID as highlighted, click on the Copy button to copy the Tenant ID. You can copy and keep it with you.

Get-AzVm  'this.Client.SubscriptionId' cannot be null how to fix

Now run the below PowerShell Script to get the Azure Virtual Machine details

$MyVM = "mynewvm"
Clear-AzContext
Connect-AzAccount -Tenant 5dxxxxx-0310-xxxx-ae8b-vvvvvvv228 -Subscription xxxxxx-dee5-4518-9c9c-xxxxxcbd1
Get-AzVm -name $MyVM

Once you will run the above script, Click on the Yes button for the confirmation to remove all the accounts and subscriptions in all sessions for the current user.

how to fix Get-AzVm  'this.Client.SubscriptionId' cannot be null
this.client.subscriptionid’ cannot be null.

Now it will prompt you to login with your Azure Credentials Enter your UserName and Password and click on the sign-in button

how to fix Get-AzVm  this.Client.SubscriptionId cannot be null

Now you can able to see below, I got the expected output i.e my Azure Virtual Machine details.

how to fix  this.Client.SubscriptionId cannot be null error

This is how we can fix the error “Get-AzVm : ‘this.Client.SubscriptionId’ cannot be null”.

You may also like following the below articles

Wrapping UP

Well, in this article, we discussed How to fix the error Get-AzVm : ‘this.Client.SubscriptionId’ cannot be null. Hope it will help you to fix your issue as well !!!

Leave a Comment