-
Notifications
You must be signed in to change notification settings - Fork 0
/
PeriodicallyDeleteResourceGroups.ps1
36 lines (33 loc) · 1.1 KB
/
PeriodicallyDeleteResourceGroups.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
workflow PeriodicallyDeleteResourceGroups
{
Write-Output "---------Logging in...---------"
Get-Date -Format o
Write-Output "-------------------------------"
try
{
"Logging in to Azure..."
Connect-AzureRMAccount –Identity
Write-Output "---------Logged in---------"
Get-Date -Format o
Write-Output "---------------------------"
}
catch {
Write-Error -Message $_.Exception
throw $_.Exception
}
Write-Output "---------Starting deleting...---------"
Get-Date -Format o
Write-Output "--------------------------------------"
$azrg = Get-AzureRmResourceGroup
foreach -parallel ($rg in $azrg)
{
if($rg.Tags.count -eq 0 -Or ($rg.Tags.count -ne 0 -And $rg.Tags["Locked"] -ne "yes"))
{
Write-Output ("Removing resource group: `"" + $rg.ResourceGroupName + "`"")
Remove-AzureRmResourceGroup -Name $rg.ResourceGroupName -Force
}
}
Write-Output "---------Deleting finished---------"
Get-Date -Format o
Write-Output "-----------------------------------"
}