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.
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 mynewvmWhen I tried executing the above PowerShell cmdlet, I got this error. You can see the error below.

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
Table of Contents
Solution
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.

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.

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

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

Now you can see below the error has been fixed successfully. I got the expected output, i.e., my Azure Virtual Machine details. Check out the screenshot below.

Wrapping UP
This article taught us how to fix the above error. I hope it will help you to fix your issue as well !!!

I am Rajkishore, and I am a Microsoft Certified IT Consultant. I have over 14 years of experience in Microsoft Azure and AWS, with good experience in Azure Functions, Storage, Virtual Machines, Logic Apps, PowerShell Commands, CLI Commands, Machine Learning, AI, Azure Cognitive Services, DevOps, etc. Not only that, I do have good real-time experience in designing and developing cloud-native data integrations on Azure or AWS, etc. I hope you will learn from these practical Azure tutorials. Read more.
