Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get the count of deployments in each resource group in each subscription
# 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
[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
Write-Output "$($rg.ResourceGroupName): $deploymentCount"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment