Skip to content

Instantly share code, notes, and snippets.

@bmoore-msft
Created May 3, 2019 18:00
Show Gist options
  • Save bmoore-msft/72845449de9bbf8f83d9e2b18fa0b232 to your computer and use it in GitHub Desktop.
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
# 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