Forum Discussion
ARM Template: Prevent VM from starting after deployment
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)
}
- jvldnFeb 11, 2021Copper ContributorLooks like an option! I’ll check tomorrow but in our case we have more vm’s in the same resource group. I’ll check if i can figure this out 🙂
Thanks!