git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/AzureHelpers/Public/List-AzVmRgSnapshots.ps1
diff options
context:
space:
mode:
Diffstat (limited to 'AzureHelpers/Public/List-AzVmRgSnapshots.ps1')
-rw-r--r--AzureHelpers/Public/List-AzVmRgSnapshots.ps139
1 files changed, 39 insertions, 0 deletions
diff --git a/AzureHelpers/Public/List-AzVmRgSnapshots.ps1 b/AzureHelpers/Public/List-AzVmRgSnapshots.ps1
new file mode 100644
index 0000000..01cfdd2
--- /dev/null
+++ b/AzureHelpers/Public/List-AzVmRgSnapshots.ps1
@@ -0,0 +1,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}'
+} \ No newline at end of file