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
|
function List-AzVmRgSnapshots {
<#
.SYNOPSIS
List the snapshots inside the resource group an Azure VM is living in.
.DESCRIPTION
If we can unambiguously determine a single VM name inside the subscription
we are logged into through the input string, we will list all snapshots
inside its hosting resource group.
TODO: Maybe filter by VM name (through .creationData.sourceResourceId)
.INPUTS
String. The VM name to identify the resource group by.
.OUTPUTS
String. Status messages and the actual AzureCLI outputs.
#>
[Alias(
'azvmsnapshotlist',
'azvmsnaplist'
)]
Param(
[Parameter(
Mandatory=$true,
ValueFromPipeline=$true,
HelpMessage="String that is a VM name or is part of one unambiguous VM",
Position=0
)
]
[ValidateLength(1,64)]
[string]
$VmName
)
$ErrorActionPreference = 'Stop'
$myvm = Find-AzVm -VmName $VmName
az snapshot list -o jsonc -g $myvm.resourceGroup `
--query '[].{creationData: creationData, diskSizeGB: diskSizeGB, diskState: diskState, encryptionType: encryption.type, hyperVGeneration: hyperVGeneration, id: id, incremental: incremental, name: name, resourceGroup: resourceGroup, publicNetworkAccess: publicNetworkAccess}'
}
|