Get Azure VM Detail by PowerShell

Get Azure VM Detail by PowerShell

You should call Select-AzureSubscription subscription name first.

It likely is defaulting to a subscription that doesnt have any virtual machines in it.

To view your current subscription names call:

Get-AzureSubscription | select SubscriptionName

Actually the answer above is only semi-correct.

This had me pulling my virutal hair out trying to do automation (which took 7 hours of manual fudging to get working!).

Simply, you have two types of virtual machine in Azure; Classic, and Resource Manager.

If you Switch-AzureMode -name AzureServiceManagement then use Get-AzureVM you will list all of the classic VMs you have created.

If you Switch-AzureMode -name AzureResourceManager then use Get-AzureVM you will list all of the Resource Manager (or new) VMs you have created.

And remember, if you are trying to do automation, then you need the VMs in the new mode available through the portal, your old VMs (classic) that you created through management are not visable in this mode and you will have to recreate them.

Get Azure VM Detail by PowerShell

Azure has two types of Management System: AzureServiceManagement (ASM) and AzureResourceManager (ARM)

In order to control these two different type of management systems you should switch between them as described in the main page of the Azure Powershell Github project page, but this is true for the azure powershell versions lower than 1.0.0, you can find more explanation in here

For those who are interested to control ARM (AzureResourceManager) with the powershell version greter than 1.0.0, they should use all Cmdlets with the following format : [Verb]-AzureRm[Noun], for example New-AzureVm becomes New-AzureRmVm, in our case Get-AzureVM became Get-AzureRmVm

In summary:

  1. Powershell versions lower than 1.0.0 you should switch between modes and use Get-AzureVM, which is very confusing in my and lots of others opinion
  2. Powershell versions equal or greater than 1.0.0 you should use Get-AzureVM for ASM and Get-AzureRmVm for ARM.

Leave a Reply

Your email address will not be published.