git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/AzureHelpers/Public/List-AzVmRgSnapshots.ps1
diff options
context:
space:
mode:
authormail_redacted_for_web 2025-07-24 15:00:20 +0200
committermail_redacted_for_web 2025-07-24 15:00:20 +0200
commit03fbf75c8e8eca13368b9e1545f2721a35af9e68 (patch)
tree010a3b34e0490bd5afab5fb11bdee60693575034 /AzureHelpers/Public/List-AzVmRgSnapshots.ps1
parent1b082205f1e98a084695b042adec5cc122ff7717 (diff)
downloadazure-helpers-03fbf75c8e8eca13368b9e1545f2721a35af9e68.tar.bz2
source was Windows Explorer only :( forgot a few scripts
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