git.lirion.de

Of git, get, and gud

aboutsummaryrefslogtreecommitdiffstats
path: root/AzureHelpers/Public/Start-AzVm.ps1
diff options
context:
space:
mode:
authormail_redacted_for_web 2025-07-24 14:49:27 +0200
committermail_redacted_for_web 2025-07-24 14:49:27 +0200
commit1b082205f1e98a084695b042adec5cc122ff7717 (patch)
treeddfc10de4f5a9f7b6732ae98d6d52cf72769f58e /AzureHelpers/Public/Start-AzVm.ps1
downloadazure-helpers-1b082205f1e98a084695b042adec5cc122ff7717.tar.bz2
InComm, rather spontaneous
Diffstat (limited to 'AzureHelpers/Public/Start-AzVm.ps1')
-rw-r--r--AzureHelpers/Public/Start-AzVm.ps144
1 files changed, 44 insertions, 0 deletions
diff --git a/AzureHelpers/Public/Start-AzVm.ps1 b/AzureHelpers/Public/Start-AzVm.ps1
new file mode 100644
index 0000000..408fb0c
--- /dev/null
+++ b/AzureHelpers/Public/Start-AzVm.ps1
@@ -0,0 +1,44 @@
+function Start-AzVm {
+ # Supply a VM name (or an unambiguous part of it) and start the machine.
+ <#
+ .SYNOPSIS
+ Start an Azure VM whose name contains the input string.
+
+ .DESCRIPTION
+ If we can unambiguously determine a single VM name inside the subscription
+ we are logged into through the input string, we will stop and deallocate
+ the machine.
+
+ This function was built as we want to have terse input and a counterpart
+ to Stop-AzVm.
+
+ .INPUTS
+ String. The name or unambiguous part of the name of the VM we intend to
+ start.
+
+ .OUTPUTS
+ String. Status messages and the actual AzureCLI outputs.
+ #>
+ 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
+ )
+ $ErrorActionPreference = 'Stop'
+ $myvm = azvmidentify -VmName $VmName
+ # Since az vm start is taking quite its time even when the machine is started, we should check ourselves whether the machine is running:
+ if ( (az vm show -d -g $myvm.resourceGroup -n $myvm.name -o json | COnvertFrom-Json).powerState.Contains('running')) {
+ Write-Host "VM $($myvm.name) (RG: $($myvm.resourceGroup)) is already running."
+ } else {
+ Write-Host "Starting $($myvm.name) (RG: $($myvm.resourceGroup)):"
+ az vm start -g $myvm.resourceGroup -n $myvm.name
+ Write-Host "...done."
+ }
+} \ No newline at end of file