Categories
Tutorials

Get a list of Azure Resources and their Sizes

You are probably here because you have painstakingly clicked on every single Azure resource in the portal to view it’s size. Using Azure PowerShell, your pain is finally over! To pull a list of all the VM’s and their respective sizes:

$ResourceGroup = "YourResourceGroupName"
$VmSizes = @{}
$Vms = Get-AzResource -ResourceGroupName $ResourceGroup -ResourceType "Microsoft.Compute/virtualMachines"
ForEach($Vm in $Vms) {
    $CurVm = Get-AzVm -Name $Vm.Name -ResourceGroupName $Vm.ResourceGroupName 
    $VmName = $CurVm.Name
    $VmSize = $CurVm.HardwareProfile.VmSize
        $VmSizes.Add($VmName, $VmSize)
}

$VmSizes

Similarly, you can pull App Services via the app service plan like so:

$ResourceGroup = "YourResourceGroupName"
$AppServicePlans = Get-AzAppServicePlan -ResourceGroupName $ResourceGroup

foreach ($AppServicePlan in $AppServicePlans ) {
    $webApps = Get-AzWebApp -AppServicePlan $AppServicePlan
    $webApps | ft @{Label="App Service Plan"; Expression={ $AppServicePlan.Name}}, 
        @{Label="Service Plan Size"; Expression={ $AppServicePlan.Sku | select-object -ExpandProperty Size }}, 
        @{Label="App Service Name"; Expression={ $_.RepositorySiteName}}
}

Enjoy!

By Greg Coffman

Technical strategist, agile evangelist, and all-around web nerd. Spends the day as Solution Architect at Sitecore. Thoughts and ideas are my own and do not represent Sitecore.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.