简体   繁体   English

通过PowerShell获取Azure VM详细信息

[英]Get Azure VM Detail by PowerShell

I am trying to run Get-AzureVM PowerShell command, it is running fine but not return any output. 我正在尝试运行Get-AzureVM PowerShell命令,它运行正常,但不返回任何输出。

Also tried in following flavor but still blank result any idea? 还尝试了以下风味,但仍然空白结果任何想法?

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

You should call Select-AzureSubscription "subscription name" first. 您应该首先调用Select-AzureSubscription "subscription name"

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

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!). 这让我把我的虚拟头发拉出来试图做自动化(需要7个小时的手工捏造才能开始工作!)。

Simply, you have two types of virtual machine in Azure; 简而言之,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. 如果您使用Switch-AzureMode -name AzureServiceManagement则使用Get-AzureVM您将列出您创建的所有经典VM。

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. 如果您使用Switch-AzureMode -name AzureResourceManager然后使用Get-AzureVM您将列出您创建的所有资源管理器(或新)VM。

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. 请记住,如果您正在尝试自动化,那么您需要通过门户网站提供的新模式下的VM,您通过管理创建的旧VM(经典)在此模式下无法访问,您必须重新创建它们。

Azure has two types of Management System: AzureServiceManagement (ASM) and AzureResourceManager (ARM) Azure有两种类型的管理系统:AzureServiceManagement(ASM)和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 为了控制这两种不同类型的管理系统,您应该按照Azure Powershell Github项目页面主页中的描述进行切换,但对于低于1.0.0azure powershell版本 ,这是正确的,您可以找到更多解释在这里

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 对于那些有兴趣使用powershell版本greter而不是1.0.0来控制ARM(AzureResourceManager)的人,他们应该使用具有以下格式的所有Cmdlet: [Verb]-AzureRm[Noun] ,例如New-AzureVm变为New-AzureRmVm ,在我们的例子中, Get-AzureVM成为了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 Powershell版本低于1.0.0你应该在模式之间切换并使用Get-AzureVM这在我和很多其他人看来都很混乱
  2. Powershell versions equal or greater than 1.0.0 you should use Get-AzureVM for ASM and Get-AzureRmVm for ARM. 如果Powershell版本等于或大于1.0.0,则应使用Get-AzureVM for ASM和Get-AzureRmVm for ARM。

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. 我发现,我需要切换我的AzureMode。

To resolve, I ran the following powershell script. 为了解决这个问题,我运行了以下powershell脚本。

Switch-AzureMode -Name AzureResourceManager

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. 如果您的脚本使用较旧的功能以及新的Azure Resource Manager cmdlet,则在AzureServiceManagement和AzureResourceManger之间切换Azure Powershell模式是一种可能的解决方案。 The switch is needed only for Microsoft Azure Powershell version 0.9.8 or older. 仅适用于Microsoft Azure Powershell 0.9.8或更早版本的交换机。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM