How to retrieve the Azure VM RAM and CPU size using PowerShell?

PowerShellMicrosoft TechnologiesSoftware & Coding

Azure VM RAM and CPU size depend on the hardware profile chosen for the VM. In this example, we will retrieve VM (TestMachine2k16) hardware profile and then we can find how much RAM or CPU is allocated to it.

To get the Size of the Azure VM,

PS C:\> $azvm = Get-AzVM -VMName 'TestMachine2k16'
PS C:\> $azvm.HardwareProfile.VmSize



You can check the above size on the Microsoft Azure website to know how much RAM and CPU are associated with it and another way using the PowerShell by using the Get-AZVmSize command.

PS C:\> $vmsize = $azvm.HardwareProfile.VmSize
PS C:\> Get-AzVMSize -VMName $azvm.Name -ResourceGroupName $azvm.ResourceGroupName | where{$_.Name -eq $vmsize}


You can see that the CPU allocated is 2, RAM is 7168 MB.

Published on 17-May-2021 12:05:32