0

I need to extract a list of vms in our subscription which also shows the cpu cores each vm has , is there a way of doing this ?

VenkateshDodda
  • 4,723
  • 1
  • 3
  • 12
itye1970
  • 1,654
  • 7
  • 31
  • 62

1 Answers1

1

You can use the below PowerShell Script, to pull the list of VM & their respective CPU Cores.

Connect-AzAccount
$vms=get-azvm | select -Property Name,ResourceGroupName,Location
foreach($vm in $vms){
     $size = (Get-AzVM -ResourceGroupName $vm.ResourceGroupName -Name $vm.Name).HardwareProfile.VmSize
     $output=Get-AzVMSize -Location $vm.Location|?{$_.Name -eq $size} | select -Property Name,NumberOfCores

     Write-Output $vm.Name,$output|Format-Table -AutoSize
}

Here is the sample Output for reference:

enter image description here

VenkateshDodda
  • 4,723
  • 1
  • 3
  • 12
  • i get get-azvm : The term 'get-azvm' is not recognized as the name of a cmdlet, function ? – itye1970 Feb 04 '22 at 10:54
  • Have you installed Az modules in your machine? if not try installing the Az Modules using this cmdlet `Install-Module -Name Az -Scope CurrentUser ` – VenkateshDodda Feb 04 '22 at 10:57
  • Get-AzVM is one of the cmdlet inside Az.Compute module here is the reference document https://learn.microsoft.com/en-us/powershell/module/az.compute/get-azvm?view=azps-7.1.0 – VenkateshDodda Feb 04 '22 at 10:59
  • i did that but all i get is nothing, i run the command, it executes but thats it no data – itye1970 Feb 04 '22 at 11:08
  • lets join this chat room & continue the discussion https://chat.stackoverflow.com/rooms/info/241719/70984312vmlist – VenkateshDodda Feb 04 '22 at 11:14
  • it works if you run via portal but not via powershell on my machine – itye1970 Feb 04 '22 at 11:15
  • @itye1970 - If my answer is helpful for you, you can accept it as answer( click on the check mark beside the answer to toggle it from greyed out to filled in.). This can be beneficial to other community members. Thank you – VenkateshDodda Feb 04 '22 at 12:40