How to Calculate Total Number of Memory in Azure VM's

863 views Asked by At

I have Azure account and I need to know how much memory is installed in all the VM's. For number of Cores, I use below command.

>Get-AzureRmVMUsage -Location WestUS

But how can I get the Memory details?

1

There are 1 answers

7
Ivan Glasenberg On

Just give you an example: How to get installed memory for each VM, and note that if you want to calculate the total number of installed memory for all VMs, just add them one by one.

#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
}

Test result:

enter image description here