我有Azure帐户,我需要知道所有VM中都安装了多少内存。对于内核数,我使用以下命令。
>Get-AzureRmVMUsage -Location WestUS
但是如何获取内存详细信息?
答案 0 :(得分:0)
仅举一个例子:如何获取每个VM的已安装内存,请注意,如果要计算所有VM的已安装内存总数,只需将它们一个个添加。
#get all the vms in the resource group, you also can get all the vms in your subscription by removing -ResourceGroupName "xxx"
$vms = Get-AzureRmVM -ResourceGroupName "xxx" -status
foreach($vm in $vms)
{
$temp = Get-AzureRmVMSize -ResourceGroupName $vm.ResourceGroupName -VMName $vm.name | where{$_.Name -eq $vm.HardwareProfile.VmSize}
#get each vm's installed memory
$vm_memory = $temp.MemoryInMB
Write-Output "VM Name: $($vm.name); VM Memory: $vm_memory"
#if you want to count all the vms' memory, you can write your own logic here
}
测试结果: