Feb 11 2021 02:15 AM
Hi all,
I just created a new Azure ARM template to deploy virtual machines. I've configured a scheduled shutdown task in it to make sure it shuts down at the end of the day.
After deploying the ARM template the virtual machine is started immediately. I want to prevent this in my ARM template if that's possible. I don't see anything in the API documentation about this: Microsoft.Compute/virtualMachines 2020-06-01 - ARM template reference | Microsoft Docs
Anyone a creative idea to prevent a VM from booting after deployment?
Feb 11 2021 12:03 PM
Hi
I don't think it's possible you can identify the resource group in wich VM to stop will be deployed and create a runbook that would have the code below so each Vm you deployed will be stopped :
Param(
[string]$VmName,
[string]$ResourceGroupName,
[ValidateSet("Startup", "Shutdown")]
[string]$VmAction
)
# Login to Automation Account
$Conn = Get-AutomationConnection -Name AzureRunAsConnection
Add-AzureRMAccount -ServicePrincipal -Tenant $Conn.TenantID `
-ApplicationID $Conn.ApplicationID -CertificateThumbprint $Conn.CertificateThumbprint | Out-Null
# Shutdown Virtual Machines
$vms = $VmName.split(',')
foreach($vm in $vms) {
IF ($VmAction -eq "Shutdown") {
Stop-AzureRmVM -Name $Vm -ResourceGroupName $ResourceGroupName -Force | Out-Null
#Write-Output "VM $Vm in Resource Group $ResourceGroupName was stopped Successfully"
$objOut = [PSCustomObject]@{
ResourceGroupName = $ResourceGroupName
VMName = $Vm
VMAction = $VmAction
}
Write-Output ( $objOut | ConvertTo-Json)
}
Feb 11 2021 12:14 PM