Get Azure VM Detail by PowerShell

2019-06-15 20:00发布

I am trying to run Get-AzureVM PowerShell command, it is running fine but not return any output.

Also tried in following flavor but still blank result any idea?

Get-AzureVM -Name "vmname" |Select-Object name,instancesize,location

5条回答
贼婆χ
2楼-- · 2019-06-15 20:39

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 VM's you have created.

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

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

查看更多
狗以群分
3楼-- · 2019-06-15 20:39

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.
查看更多
放我归山
4楼-- · 2019-06-15 20:54

You should call Select-AzureSubscription "subscription name" first.

It likely is defaulting to a subscription that doesn't have any virtual machines in it.

To view your current subscription names call:

Get-AzureSubscription | select SubscriptionName
查看更多
祖国的老花朵
5楼-- · 2019-06-15 20:54

I know this question has been answered but I tried the answer given and it did not work for me. I found, I needed to switch my AzureMode.

To resolve, I ran the following powershell script.

Switch-AzureMode -Name AzureResourceManager

查看更多
闹够了就滚
6楼-- · 2019-06-15 20:54

Switching Azure Powershell mode between AzureServiceManagement and AzureResourceManger is a possible solution if your script is using older features as well as new Azure Resource Manager cmdlets. The switch is needed only for Microsoft Azure Powershell version 0.9.8 or older.

查看更多
登录 后发表回答