This is a powershell
script which analyses deployments in resource groups for a subscription.
The purpose of this is to clean up old deployments and avoid hitting the 800 max deployments hard limit per resource group.
By default, this will analyse resource groups but not delete anything. Deletion is enabled via the -delete
flag.
Only resource groups where the name starts with Dev-
will be affected.
.\deployment-maid.ps1 `
-subscriptionId subId `
-resourceGroupNamePattern "Dev-*" `
-maxAgeDays 30
Add the -delete
flag to also delete the listed deployments.
.\deployment-maid.ps1 `
-subscriptionId subId `
-resourceGroupNamePattern "Dev-*" `
-maxDeploymentsPerGroup 100 `
-delete
Name | Value | Description |
---|---|---|
subscriptionId | string | Azure subscription Id |
resourceGroupNamePattern | string | Filters resource groups based on their name. Wildcards supported. E.g. A single resource group: "MyResourceGroup" All groups: "\*" All groups starting with Dev-: "Dev-\*" |
Name | Value | Description |
---|---|---|
ignoredResourceGroups | String | Comma-separated list of resource groups to ignore. E.g. "Group1, Group2". Applied after finding groups with resourceGroupNamePattern. |
maxAgeDays | Int | Deployments older than this number of days will be deleted. Set to -1 to ignore. Default: -1 |
maxDeploymentsPerGroup | Int | Ensure that no resource group has more deployments than this. Default: 800 |
Name | Description |
---|---|
delete | Delete highlighted deployments |
skipLogin | Skip login and use existing session. If running the script multiple times, use this after the first run |
- Deployments are deleted from oldest to newest
- Deletions will start with the groups that have the most amount of items to delete
- The names and times of deleted deployments are output as they are deleted