To list all the Azure VMs connected to the particular subscription, we need to use the “Az vm” command. Before that, we need to make sure the Azure is connected to the desired subscription, if not use the below command to set the Azure Subscription.
az account set -s 'subscription name or id'
Once the Azure subscription is set, we can use the below command to retrieve the Azure VMs.
PS C:\> az vm list -otable
To get the particular azure VM using CLI, we need to provide the VM name and resource group name.
PS C:\> az vm show -n VmName -g ResourceGroupName -otable
“az vm show” command finds the VM from the list using parameter -n (VMName) -g (resource group Name).