0

Is there a way to enable the Auto-start feature on a DevTest Labs virtual machine as part of the creation i.e. can it be added to the VM's ARM template?

I enable this manually via the Azure portal currently, but I'm finding that it gets disabled when subsequent deployments from Team Services are made.

Solution

Inspired by the accepted answer from Ashok below, I've managed to tweak and simplify the PowerShell script to the following...

Param([string] $resourceId)

$tags = (Get-AzureRmResource -ResourceId $resourceId).Tags

if (-Not ($tags) -Or -Not($tags.ContainsKey('AutoStartOn'))) {
  $tags += @{ AutoStartOn=$true; }
}

if (-Not ($tags) -Or -Not($tags.ContainsKey('AlwaysOn'))) {
  $tags += @{ AlwaysOn=$true; }
}

Set-AzureRmResource -ResourceId $resourceId -Tag $tags -Force
smd
  • 352
  • 3
  • 15
  • How do you subsequent deployments from Team Services? – starian chen-MSFT Oct 19 '17 at 01:26
  • As part of the release definition in Team Services, we use the **DevTest Labs Create VM** task to ensure the machine is available before deployemnt. I can only assume this process is what is causing the machines to lose their **auto-start** tag. Maybe due to the ARM template supplied during VM creation? Perhaps there's another way to handle this such as the PowerShell in Ashok's answer below. – smd Oct 19 '17 at 06:41
  • Could you get necessary information through Get-AzureRmResource command? `$VmResourceId = "subscriptions/$subscriptionId/resourcegroups/$labResourceGroup/providers/microsoft.devtestlab/labs/$labName/virtualmachines/$VmName" $vm = Get-AzureRmResource -ResourceId $VmResourceId -ExpandProperties` – starian chen-MSFT Oct 19 '17 at 07:23

0 Answers0