Created
May 3, 2019 18:00
-
-
Save bmoore-msft/72845449de9bbf8f83d9e2b18fa0b232 to your computer and use it in GitHub Desktop.
Get the count of deployments in each resource group in each subscription
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# use this script to get all the deployments in all subscriptions the current user context has access to - it can | |
# be useful to find groups that are close to the 800 limit | |
param( | |
[int]$deploymentCountWarningLevel = 700 # number of deployments where a warning should be written | |
) | |
Disable-AzContextAutosave -Verbose | |
$subs = Get-AzSubscription | |
foreach($sub in $subs){ | |
Select-AzSubscription -Subscription "$sub" | |
$rgs = Get-AzResourceGroup | |
foreach($rg in $rgs){ | |
$deploymentCount = (Get-AzResourceGroupDeployment -ResourceGroupName $rg.ResourceGroupName).count | |
if($deploymentCount -ge $deploymentCountWarningLevel){ | |
Write-Warning "$($rg.ResourceGroupName) contains: $deploymentCount deployments" | |
Write-Warning $rg.ResourceId | |
} | |
Else{ | |
Write-Output "$($rg.ResourceGroupName): $deploymentCount" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment