Azure - Get number of cores for all VMs within a specific resource group
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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