Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. param(
  2. [Parameter(Mandatory = $false, Position = 1)]
  3. [int]
  4. $Keep = 100
  5. )
  6.  
  7. Get-AzureRmResourceGroup | ForEach-Object {
  8. $ts = (Get-AzureRmResourceGroupDeployment -ResourceGroupName $_.ResourceGroupName |
  9. Sort-Object Timestamp -Descending |
  10. Select-Object -First $Keep |
  11. Select-Object -Last 1).Timestamp
  12. if ($ts) {
  13. Write-Host "delete from" $_.ResourceGroupName "older than " $ts
  14. Get-AzureRmResourceGroupDeployment -ResourceGroupName $_.ResourceGroupName |
  15. Where-Object {$_.Timestamp -lt $ts} |
  16. Remove-AzureRmResourceGroupDeployment
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement