Have you ever struggled to find out how many VM cores, HDInsight cores, storage accounts, or other Azure resources your subscription is set to allow or how many you actually use? Maybe you want to use this information in your automation scripts to avoid trying to create components for which you don’t have resources.
PowerShell to the rescue!
First a couple of key points. There are various maximums in Azure. Today we are talking about finding the currently configured maximums allowed for a specified subscription. There are default maximums (default limit) which you can increase for a given subscription by opening a billing support ticket. There are also hard maximums (maximum limit). However, with some products, such as HDInsight (Hadoop), you can get past some per-subscription maximums for dependent services by combining resources (storage accounts) from multiple subscriptions for a single HDInsight cluster. All the samples below find the current billing quota limitation and actual usage for the current subscription.
Let’s take a look at the information available on the subscription level cmdlet.
Start by checking which subscription is in focus / current for the PowerShell session.
If you need information on a different subscription either pass the subscription name (as defined on your client) for the cmdlets that support this or change the focus to a different subscription.
$SubName = "sqlcatwoman"
Select-AzureSubscription -SubscriptionName $SubName
Now we will look at the cores available for Azure virtual machines (VMs / IaaS). Note that HDInsight cores are tracked separately. Be careful with unexpected line wraps that may paste into your PowerShell window (or ISE) incorrectly. The below snippet is 1 comment line and 4 lines of code.
# How many cores are available to create new VMs (or increase size of existing VMs) for the current subscription?
[int]$maxVMCores = (Get-AzureSubscription -current -ExtendedDetails).maxcorecount
[int]$currentVMCores = (Get-AzureSubscription -current -ExtendedDetails).currentcorecount
[int]$availableCores = $maxVMCores - $currentVMCores
Write-Host "Cores available for VMs:" $availableCores
We can get similar information about cloud services:
#how many cloud (hosted) services are available on this subscription
[int]$maxAvl = (Get-AzureSubscription -current -ExtendedDetails).MaxHostedServices
[int]$currentUsed = (Get-AzureSubscription -current -ExtendedDetails).CurrentHostedServices
[int]$availableNow = $maxAvl - $currentUsed
Write-Host "Cloud services available:" $availableNow
Some limits and usage are available on cmdlets specific to a particular technology. For example, the HDInsight usage and maximums are available from the Get-AzureHDInsightProperties cmdlet. You can find details and samples on Get HDInsight Properties with PowerShell.
Other times we have to look at different cmdlets for different pieces of the information, such as for storage accounts:
#how many storage accounts are available on this subscription
[int]$maxAvl = (Get-AzureSubscription -current -ExtendedDetails).MaxStorageAccounts
[int]$currentUsed = (Get-AzureStorageAccount).Count
Write-Host "Storage Accounts available:" $availableNow
We can look at all the extended properties available for a subscription:
Get-AzureSubscription -current –ExtendedDetails
If you know you have a particular component created and this cmdlet shows the “Current” value is zero, take a look at the Get-Azure… cmdlet for that particular type of resource and look for a “Current” value.
Another handy thing to look at is the overall information about what Azure regions exist and what services are available in each region:
And you can pull off specific information:
Get-AzureLocation | Select DisplayName
I hope these small bites of PowerShell help save the day for you in some way!
Very Useful information, Thanks