git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
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
parent1b082205f1e98a084695b042adec5cc122ff7717 (diff)
downloadazure-helpers-03fbf75c8e8eca13368b9e1545f2721a35af9e68.tar.bz2
source was Windows Explorer only :( forgot a few scripts
-rw-r--r--AzureHelpers/Public/List-AzVmRgSnapshots.ps139
-rw-r--r--AzureHelpers/Public/New-AzVmOsSnapshot.ps151
-rw-r--r--AzureHelpers/Public/Remove-AzVmRgSnapshots.ps148
3 files changed, 138 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
diff --git a/AzureHelpers/Public/New-AzVmOsSnapshot.ps1 b/AzureHelpers/Public/New-AzVmOsSnapshot.ps1
new file mode 100644
index 0000000..dcf6535
--- /dev/null
+++ b/AzureHelpers/Public/New-AzVmOsSnapshot.ps1
@@ -0,0 +1,51 @@
+function New-AzVmOsSnapshot {
+ <#
+ .SYNOPSIS
+ Create a snapshot of the OS disk of an Azure VM.
+
+ .DESCRIPTION
+ If we can unambiguously determine a single VM name inside the subscription
+ we are logged into through the input string, we will create a snapshot
+ of its OS disk.
+
+ .INPUTS
+ System.Object. @{ VmName = VMNAME; SnapshotName = SNAPSHOTNAME }
+
+ .OUTPUTS
+ String. Status messages and the actual AzureCLI outputs.
+ #>
+ [Alias(
+ 'Create-AzVmOsSnapshot',
+ 'azvmsnapshot',
+ 'azvmsnap'
+ )]
+ Param(
+ [Parameter(
+ Mandatory=$true,
+ ValueFromPipelineByPropertyName=$true,
+ HelpMessage="String that is a VM name or is part of one unambiguous VM",
+ Position=0
+ )
+ ]
+ [ValidateLength(1,64)]
+ [string]
+ $VmName,
+ [Parameter(
+ Mandatory=$true,
+ ValueFromPipelineByPropertyName=$true,
+ HelpMessage="Name of the snapshot",
+ Position=1
+ )
+ ]
+ [ValidateLength(1,64)]
+ [string]
+ $SnapshotName
+ )
+ $ErrorActionPreference = 'Stop'
+ $myvm = Find-AzVm -VmName $VmName
+ $myDisk = (az vm show -g $myvm.resourceGroup -n $myvm.name --query "storageProfile.osDisk.managedDisk.id" -o json | ConvertFrom-Json)
+ Write-Host "Identified VM: ${myvm.name}"
+ Write-Host "Creating OS disk snapshot `"${SnapshotName}`""
+ az snapshot create -o jsonc -g $myvm.resourceGroup --source $myDisk --name $SnapshotName `
+ --query '[].{creationData: creationData, diskSizeGB: diskSizeGB, encryptionType: encryption.type, hyperVGeneration: hyperVGeneration, id: id, name: name, resourceGroup: resourceGroup, publicNetworkAccess: publicNetworkAccess}'
+} \ No newline at end of file
diff --git a/AzureHelpers/Public/Remove-AzVmRgSnapshots.ps1 b/AzureHelpers/Public/Remove-AzVmRgSnapshots.ps1
new file mode 100644
index 0000000..b458c84
--- /dev/null
+++ b/AzureHelpers/Public/Remove-AzVmRgSnapshots.ps1
@@ -0,0 +1,48 @@
+function Remove-AzVmRgSnapshot {
+ <#
+ .SYNOPSIS
+ Delete a snapshot 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 remove a snapshot
+ with a given name.
+
+ .INPUTS
+ System.Object. @{ VmName = VMNAME; SnapshotName = SNAPSHOTNAME }
+
+ .OUTPUTS
+ String. Status messages and the actual AzureCLI outputs.
+ #>
+ [Alias(
+ 'Delete-AzVmOsSnapshot',
+ 'azvmsnapdel'
+ )]
+ Param(
+ [Parameter(
+ Mandatory=$true,
+ ValueFromPipelineByPropertyName=$true,
+ HelpMessage="String that is a VM name or is part of one unambiguous VM",
+ Position=0
+ )
+ ]
+ [ValidateLength(1,64)]
+ [string]
+ $VmName,
+ [Parameter(
+ Mandatory=$true,
+ ValueFromPipelineByPropertyName=$true,
+ HelpMessage="Name of the snapshot",
+ Position=1
+ )
+ ]
+ [ValidateLength(1,64)]
+ [string]
+ $SnapshotName
+ )
+ $ErrorActionPreference = 'Stop'
+ $myvm = Find-AzVm -VmName $VmName
+ Write-Host "Identified VM: ${myvm.name}"
+ Write-Host "Deleting OS disk snapshot `"${SnapshotName}`""
+ az snapshot delete -o jsonc -g $myvm.resourceGroup --name $SnapshotName
+} \ No newline at end of file