Created
March 20, 2019 04:54
-
-
Save KaiWalter/fd2b73945b4eae55483284d875b28b0b to your computer and use it in GitHub Desktop.
remove ResourceGroupDeployments up to a given limit
This file contains hidden or 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
| param( | |
| [Parameter(Mandatory = $false, Position = 1)] | |
| [int] | |
| $Keep = 100 | |
| ) | |
| Get-AzureRmResourceGroup | ForEach-Object { | |
| $ts = (Get-AzureRmResourceGroupDeployment -ResourceGroupName $_.ResourceGroupName | | |
| Sort-Object Timestamp -Descending | | |
| Select-Object -First $Keep | | |
| Select-Object -Last 1).Timestamp | |
| if ($ts) { | |
| Write-Host "delete from" $_.ResourceGroupName "older than " $ts | |
| Get-AzureRmResourceGroupDeployment -ResourceGroupName $_.ResourceGroupName | | |
| Where-Object {$_.Timestamp -lt $ts} | | |
| Remove-AzureRmResourceGroupDeployment | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment