-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRemove-SnapshotsForLab.ps1
37 lines (26 loc) · 1 KB
/
Remove-SnapshotsForLab.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
param
(
[Parameter(Mandatory=$true, HelpMessage="Name of lab to remove snapshots from")]
[string] $DevTestLabName,
[Parameter(Mandatory=$true, HelpMessage="RG of lab to remove")]
[string] $ResourceGroupName,
[Parameter(valueFromRemainingArguments=$true)]
[String[]]
$rest = @()
)
$ErrorActionPreference = "Stop"
. "./Utils.ps1"
Write-Host "Removing snapshots for lab $DevTestLabName in $ResourceGroupName"
$snapshots = Get-AzureRmResource -ResourceType 'Microsoft.DevTestLab/labs/customImages' -ResourceName $DevTestLabName -ResourceGroupName $ResourceGroupName -ApiVersion '2016-05-15'
if(-not $snapshots) {
return "No snapshots to remove in $DevTestLabName"
}
$jobs = @()
$snapshots | ForEach-Object {
$sb = {
Remove-AzureRmResource -ResourceId ($Using:_).ResourceId -Force -ApiVersion '2016-05-15' | Out-Null
}
$jobs += Start-RSJob -ScriptBlock $sb -Name $DevTestLabName
}
Wait-RSJobWithProgress -secTimeout (1 * 60 * 60) -jobs $jobs
Write-Output "Snapshot deleted for $DevTestLabName"