Reputation: 6132
Using 1.0.1, running the below script does not generate errors. However, after viewing the VM Tags in the Preview Portal GUI, the tags do not show. What did I miss?
$tags = (Get-AzureRmResource -ResourceGroupName "myresourcegroup" -ResourceType "Microsoft.Compute/virtualMachines" -Name "myserver").Tags
$tags += @{Name1="name1";Value1="value1"}
$tags += @{Name2="name2";Value2="value2"}
$tags += @{Name3="name3";Value3="value3"}
$tags += @{Name4="name4";Value4="value4"}
Set-AzureRmResource -ResourceGroupName "myresourcegroup" -Name "myserver" -Tag $tags -ResourceType "Microsoft.Compute/virtualMachines"
Confirm:
Are you sure you want to update the following resource:
/subscriptions/{guid}/resourceGroups/myresourcegroup/providers/Microsoft.Compute/virtualMachines/myserver
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y
Output:
Name : b5bd3server044
ResourceId : /subscriptions/{guid}/resourceGroups/myresourcegroup/providers/Microsoft.Compute/virtualMachines/myserver
ResourceName : myserver
ResourceType : Microsoft.Compute/virtualMachines
ResourceGroupName : myresourcegroup
Location : eastus2
SubscriptionId : {guid}
Tags : {}
Properties : @{VmId={guid}; HardwareProfile=; StorageProfile=; OsProfile=; NetworkProfile=;
DiagnosticsProfile=; ProvisioningState=Succeeded}
Upvotes: 0
Views: 701
Reputation: 6255
I have tested your code and found out the root cause of the issue.
It is because your new tags object properties are wrong, i.e. Name1, Value1...
You should use Name and Value as the tag properties only.
$tags += @{Name="name1";Value="value1"}
$tags += @{Name="name2";Value="value2"}
$tags += @{Name="name3";Value="value3"}
$tags += @{Name="name4";Value="value4"}
With just this fix you code should work perfectly fine.
Here is a good resource from Microsoft on using tags with Azure resources.
Using tags to organize your Azure resources
Hope it helps.
Upvotes: 1