Search code examples
azure-virtual-machineazure-powershellazure-automation

Unable to set tags for azure virtual machine from Azure automation runbook


I am using the below code to set TAGs to my Azure virtual machine. The code is working when I am running it on my laptop (VM are getting tagged). However, when I run the same code from Azure Automation runbook, the virtual machines are not getting tagged. No errors or warnings observed post runbook execution.

Code:

$resource_group = "agentinstall-poc"

$tags = (Get-AzureRmResource -ResourceGroupName $resource_group -Name "client-2").Tags

$tags += @{manju="rao"}


Set-AzureRmResource -ResourceGroupName $resource_group -Name "client-2" -ResourceType "Microsoft.Compute/VirtualMachines" -Tag $tags -Force -ApiVersion '2015-06-15'

Solution

  • The problem was that the PowerShell modules in the Azure automation account are not updated by default (they are v1.0 ish when the account gets created). I had to update the modules and they started working.