【问题标题】:Azure Powershell - Can't find classic VMsAzure Powershell - 找不到经典 VM
【发布时间】:2017-04-23 22:52:23
【问题描述】:

我正在尝试通过 PowerShell 检索 VM 的完整列表,但我无法提取经典 VM,而且我无法理解 RM 和常规 cmdlet 之间的区别,尤其是在订阅方面。

Get-AzureRMSubscription 正确返回了我的 Azure 帐户有权访问的订阅的完整列表。 Get-AzureSubscription 什么也不返回。这意味着我可以使用 Get-AzureRMVM 从任何订阅中正确提取所有新样式的 VM,但是由于我找不到“经典”样式订阅,因此我无法拉出任何现有的经典 VM '不定义要查看的订阅。

我可以通过门户成功查看所有订阅中的所有虚拟机,但无论出于何种原因都无法通过 Powershell。我完全没有想法,有什么我遗漏的吗?

【问题讨论】:

标签: powershell azure


【解决方案1】:

Get-AzureRMSubscription Get-AzureSubscription Get-AzureRMVM 是资源模式 cmdlet,您的 VM 是经典模式 VM,您应该使用经典 cmdlet。只需使用以下 cmdlet。

#login your classic account
Add-AzureAccount
# Enumerates all configured subscriptions on your local machine.
Get-AzureSubscription  
# Select the subscription to use
Select-AzureSubscription -SubscriptionName "mysubscription" 
#get classic VM
Get-AzureVM

【讨论】:

  • 如 OP 中所述,Get-AzureSubscription 不返回任何内容,因此 Select-AzureSubscription 失败,因为它找不到要分配的订阅,因此 Get-AzureVM 失败,因为订阅尚未已分配。
  • @CNoyer 您在 Portal 和 PowerShell 上使用相同的帐户吗?您能否提供一些有关您在 Portal 上的 VM 的屏幕截图?此外,您可以检查您的 PowerShell 版本。 Get-Module -ListAvailable -Name Azure -Refresh最新版本为3.7.0
  • 这可能是因为当您使用 add-AzureAccount 时,您正在登录您的个人 Microsoft 帐户,并且您的订阅是在您的工作帐户上,反之亦然。当您使用 Add-AzureAccount 登录 Microsoft 时,您有两个选项工作或个人。确保选择订阅有效的那个。
  • 新虚拟机和经典虚拟机都可以通过 GUI 门户完全查看,两者都使用相同的帐户。我确保我的 Powershell Azure 版本是最新的,所以这不是问题。
  • @CNoyer 您使用哪个 Azure 区域? AzureCloud for global Azure ,AzureChinaCloud for Azure 由 21Vianet 在中国运营还是 Azure 在德国运营?如果您不使用全局 Azure,则登录时应使用Add-AzureAccount -Environment AzureGermanCloud。此 cmdlet 用于登录 Azure for Germany。
【解决方案2】:

经典 VM 是使用 Azure 使用 manage.windowsazure.com 时的标准,其中,默认情况下,每个虚拟机都附加一个云服务,并且虚拟网络和防火墙 (ACL) 等资源对于每个资源都是静态的。

基于 Azure 资源管理器 (ARM) 的部署使您能够拥有灵活的部署模型(例如,一个防火墙/NSG 用于 x 数量的 VM)。详细的研究可以在下面的链接中找到:

Azure Resource Manager based deployments explained

对于您的问题,您可以使用以下 Cmdlet 获取所有经典虚拟机。

#login your classic (work AD / Personal) account using the pop-up
Add-AzureAccount
# Get All subscriptions under the non-rm account. DO NOT USE Get-AzureRMSubscription for any classic resources

Get-AzureSubscription  
# Select the subscription to use using the Subscription name or ID (if all your subscription names say pay-as-you-go for e.g. you may want to use your subscription ID)

Select-AzureSubscription -SubscriptionName "enter-your-subscription-name" OR -SubscriptionId "alternatively-use-subscription-id"

#List all the VM's in a variable for further use (if needed, else direct display)

$vmList = Get-AzureVM

#Output the Virtual Machines on the subscription

Write-Output ($vmList)

完成!

【讨论】:

  • 如 OP 中所述,Get-AzureSubscription 不返回任何内容,因此 Select-AzureSubscription 失败,因为它找不到要分配的订阅,因此 Get-AzureVM 失败,因为订阅尚未已分配。
  • 这可能是因为当您使用 add-AzureAccount 时,您正在登录您的个人 Microsoft 帐户,并且您的订阅是在您的工作帐户上,反之亦然。当您使用 Add-AzureAccount 登录 Microsoft 时,您有两个选项工作或个人。确保选择订阅有效的那个。
  • 专门为此功能创建了一个帐户 - 一个通用 VM 管理员帐户 - 所以不可能是这种情况。
猜你喜欢
  • 1970-01-01
  • 2018-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-06-16
  • 2016-10-31
  • 2016-03-19
  • 1970-01-01
相关资源
最近更新 更多