Syntax error How to change the Azure tag value using PowerShell?

How to change the Azure tag value using PowerShell?



To change the azure value using PowerShell we need to use the Update-AZTag command with the merge property.

Example

For example, we have the Azure VM TestMachine2k16 and we have its tags as shown below.

PS C:\> $vm = Get-AzVM -VMName TestMachine2k16
PS C:\> $vm | Select -ExpandProperty Tags

Output

Key          Value
---          -----
Owner        Chirag
For Ansible
Patching_Day Sunday
Application SecretTag

We need to change the Patching_Day from Sunday to Wednesday. We will use the below command.

Example

$tag = @{Patching_Day='Wednesday'}
Update-AzTag -Tag $tag -ResourceId $vm.Id -Operation Merge -Verbose

Output

Name           Value
============   =========
Patching_Day   Wednesday
For            Ansible
Application    SecretTag
Owner          Chirag

There is also property Replace available in Update-AZTag but please be cautious while using the Replace parameter because once you apply it, the current tag will be changed but other tags will be erased.

Example

Update-AzTag -Tag $tag -ResourceId $vm.Id -Operation Replace -Verbose

Output

Properties :
Name          Value
============  =========
Patching_Day  Wednesday
Updated on: 2021-04-06T07:59:15+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements