azure - 如何计算 Azure VM 中的内存总数
问题描述
我有 Azure 帐户,我需要知道所有 VM 中安装了多少内存。对于核心数,我使用以下命令。
>Get-AzureRmVMUsage -Location WestUS
但是我怎样才能获得内存详细信息?
解决方案
举个例子:如何获取每个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
}
测试结果:
推荐阅读
- ruby-on-rails - Rails hidden_field 不生成值,尽管它可以在视图中呈现
- github - 我在哪里可以找到需要贡献者的开源项目?
- python - 我正在检查和升级我的 keras ans tensorflow 包,但我仍然遇到同样的错误
- go - gomock 未接来电
- php - foreach() 参数必须是数组|对象类型,在 laravel 8 中给出 null
- javascript - How do modern editors handle text buffers?
- docker - Jenkins: [internal] load metadata for docker.io/library/openjdk:8-jdk-alpine:
- java - Cannot update the value of the same label twice inside same block
- css - React Build Tailwind Not Including all classes
- android-recyclerview - RecyclerView and Item Position and click on particular item