-
Notifications
You must be signed in to change notification settings - Fork 2
/
Clean.ps1
41 lines (35 loc) · 1.18 KB
/
Clean.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
37
38
39
40
41
[CmdletBinding()]
Param(
[string]$ManagedImageName,
[string]$ManagedImageResourceGroupName,
[string]$AgentPoolResourceGroup,
[switch]$RemovePackerResourceGroups,
[switch]$RemoveManagedImages,
[switch]$RemoveAgentPoolResourceGroup
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
if ( $RemovePackerResourceGroups) {
"Removing all temporary Packer resource groups"
Get-AzureRmResourceGroup | Where-Object ResourceGroupName -like packer-resource-group-* | Remove-AzureRmResourceGroup -Force
}
else {
"Skip removing Packer resource groups"
}
if ( $RemoveManagedImages) {
"Remove Managed Image $ManagedImageName in $ManagedImageResourceGroupName"
Remove-AzureRmImage -ResourceGroupName $ManagedImageResourceGroupName -ImageName $ManagedImageName -Force
}
else {
"Skip removing managed images"
}
if ( $RemoveAgentPoolResourceGroup) {
"Remove agent pool resource group $AgentPoolResourceGroup"
Get-AzureRmResourceGroup -Name $AgentPoolResourceGroup -ev notPresent -ea 0
if (-Not $notPresent) {
Remove-AzureRmResourceGroup -Name $AgentPoolResourceGroup -Force
}
}
else {
"Skip removing agent pool resource group"
}