Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list of all Azure VMs in Powershell

I'm attempting to get a list of all my Azure VMs in Powershell.

Get-AzureVM

Unfortunately this only returns the VMs listed under Virtual machines (classic).

enter image description here

How can I get a list of the new Virtual machines?

like image 667
Jon Crowell Avatar asked Oct 15 '25 06:10

Jon Crowell


1 Answers

Based on David's answer, I wrote the following script that combines the two lists of VMs:

Switch-AzureMode -Name AzureServiceManagement
#ResourceGroupName will be blank for these
$classicVms = Get-AzureVM | select Name, ServiceName, ResourceGroupName

Switch-AzureMode -Name AzureResourceManager    
#ServiceName will be blank for these
$armVms = Get-AzureVM | select Name, ServiceName, ResourceGroupName 

$allVms = $classicVms + $armVms
$allVms

When you run this, you'll get a warning that Switch-AzureMode is deprecated.

WARNING: The Switch-AzureMode cmdlet is deprecated and will be removed in a future release

The deprecation is part of a breaking change. You can read the details here: Deprecation of Switch-AzureMode.

like image 129
Jon Crowell Avatar answered Oct 18 '25 01:10

Jon Crowell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!