Skip to content

Instantly share code, notes, and snippets.

Last active August 19, 2022 14:43
What would you like to do?
Azure - Get number of cores for all VMs within a specific resource group
# Make sure to run Connect-AzAccount first
$Subscription = "SUBSCRIPTION_NAME"
$Location = "REGION_NAME"
$ResourceGroup = "RESOURCE_GROUP_NAME"
Set-AzContext -SubscriptionName $Subscription | Out-Null
$TotalCores = $null
$TotalWorkers = (Get-AzVM -ResourceGroupName $ResourceGroup -Status | Where-Object { (
$_.ProvisioningState -eq "Succeeded" ) })
foreach ($Worker in $TotalWorkers) {
$VMSize = (Get-AzVM -ResourceGroupName $ResourceGroup -Name $Worker.Name).HardwareProfile.VmSize
$Cores = (Get-AzVMSize -location $Location | Where-Object { $ -eq $VMSize }).NumberOfCores
$TotalCores += $Cores
Write-Host "Total number of cores: $TotalCores"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment