首页 > 解决方案 > 通过 Powershell 脚本检查具有不同资源的已停止 VM

问题描述

如何通过 azure powershell 脚本检查已停止的具有不同资源的虚拟机 iam 尝试执行该脚本,请帮助我

标签: azure

解决方案


要获取虚拟机的状态,您可以尝试以下脚本:

 #login 
Connect-AzureRmAccount
Select-AzureRmSubscription –SubscriptionName 'subscription-name'
Get-AzureRmVM -Status | Format-Table

如果您希望 ResourceGroup 组明智,请尝试以下脚本:

Connect-AzureRmAccount
Select-AzureRmSubscription –SubscriptionName 'subscription-name'
$RG = "ResourceGroupName"
$VM = "vmname"
$VMStats = (Get-AzureRmVM -Name $VM -ResourceGroupName $RG -Status).Statuses
($VMStats | Where Code -Like 'PowerState/*')[0].DisplayStatus 

推荐阅读