Checking resource limits, quotas, and constraints using PowerShell

Jason Crawford 0 Reputation points
2023-01-24T16:01:23.11+00:00

I am seeking a solution to check for resource limit quotas that have been reached in multiple subscriptions using Lighthouse. Has anyone found a way to accomplish this using PowerShell, Graph, or other methods? Essentially, I am looking for a way to loop through each subscription and output any limits that have been reached. I have added some code on the kind of thing I am trying do. Please note, the provided code is for demonstration purposes only and may contain incorrect commands



Copy
Get-AzSubscription | Where-Object {$_.QuotaInfo.ResourceLimits.Count -gt 0} | ForEach-Object {
    Write-Host "Subscription: $( $_.Name )"
    $_.QuotaInfo.ResourceLimits | ForEach-Object {
        Write-Host "    Resource: $( $_.ResourceName )"
        Write-Host "    Limit: $( $_.Limit )"
        Write-Host "    Current Usage: $( $_.CurrentUsage )"
    }
}
# Get all subscriptions
$subscriptions = Get-AzSubscription

# Loop through each subscription
foreach ($subscription in $subscriptions) {
    # Select the subscription
    Select-AzSubscription -SubscriptionId $subscription.Id

    # Get resource limits for the subscription
    $resourceLimits = Get-AzResourceProvider -ListAvailable | Where-Object {$_.ResourceTypes.Quota -ne $null}

    # Loop through each resource limit
    foreach ($resourceLimit in $resourceLimits) {
        # Check if the limit has been reached
        if ($resourceLimit.CurrentValue -ge $resourceLimit.Limit) {
            # Output the subscription name and resource limit
            Write-Output "Subscription: $($subscription.Name)"
            Write-Output "Resource: $($resourceLimit.ResourceType)"
            Write-Output "Limit: $($resourceLimit.Limit)"
            Write-Output "Current Usage: $($resourceLimit.CurrentValue)"
        }
    }
}

Microsoft Partner Center API
Microsoft Partner Center API
Microsoft Partner Center: A Microsoft website for partners that provides access to product support, a partner community, and other partner services.API: A software intermediary that allows two applications to interact with each other.
344 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,577 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 44,371 Reputation points
    2023-01-25T19:08:08.91+00:00

    Hi,

    Thank you for posting your query.

    Kindly follow the steps provided below to resolve your issue.

    This article describes resource quota errors that might occur when you deploy resources with an Azure Resource Manager template (ARM template) or Bicep file.

    Go to this link for your reference and other troubleshooting procedures https://learn.microsoft.com/en-us/azure/azure-resource-manager/troubleshooting/error-resource-quota

    Do not hesitate to message us if you need further assistance.

    If the answer is helpful kindly click "Accept as Answer" and up vote it.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.