Skip to content

Instantly share code, notes, and snippets.

@mikerodionov
Last active August 19, 2022 14:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikerodionov/a94e5a2ca2f643d552778313624861e3 to your computer and use it in GitHub Desktop.
Save mikerodionov/a94e5a2ca2f643d552778313624861e3 to your computer and use it in GitHub Desktop.
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 { $_.name -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