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)"
}
}
}