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"
$Vms = Get-AzVM -ResourceGroupName $ResourceGroup 
$Vms | ft @{Label="Name"; Expression= { $_.Name}},
    @{Label="VM Size"; Expression= { $_.HardwareProfile.VmSize}}

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

Set-AzContext -Subscription "YourSubscriptionName"
$ResourceGroup = "YourResourceGroupName"

$AppServicePlans = Get-AzAppServicePlan -ResourceGroupName $ResourceGroup
$SqlServers = Get-AzSqlServer -ResourceGroupName $ResourceGroup


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

foreach ($SqlServer in $SqlServers) {
    $databases = Get-AzSqlDatabase -ResourceGroupName $ResourceGroup -ServerName $SqlServer.ServerName
    $databases | ft @{Label="Database Name"; Expression={ $_.DatabaseName}},
    @{Label="Edition"; Expression={ $_.Edition}},
    @{Label="Service Objective Name"; Expression={ $_.RequestedServiceObjectiveName}}
}

By Greg Coffman

Technical strategist, agile evangelist, and all-around web nerd. Formerly a Solution Architect at Sitecore. Thoughts and ideas are my own and do not represent my employer.

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.