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.

'this.client.subscriptionid' cannot be null.

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

First, 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 log in to the Azure Portal, click on the portal Menu as highlighted below. then, from the left navigation, click on Cost Management + Billing. On the Overview tab, you can see the Subscription ID as highlighted below. Now copy this ID and keep it with you.

this.client.subscriptionid' cannot be null. azure powershell

Now, 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 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.

this.client.subscriptionid' cannot be null

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 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.

'this.client.subscriptionid' cannot be null

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

this.client.subscriptionid' cannot be null. azure powershell

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

this.client.subscriptionid' cannot be null

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

Wrapping UP

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