Open In App

Microsoft Azure – Assigning Tags to a Azure VM

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will look into the process of assigning tags to an Azure VM using the Azure PowerShell commands. You can perform the commands in Azure Cloud Shell or Use can use Windows PowerShell to run the commands. 

Before Assigning the Tags to Azure Virtual Machine, You can check which are assigned to an Azure VM by using the below command.

Command:

Get-AzureRmVM | Select-Object -Property Name, ResourceGroupName, Type, Tags

It returns the properties of Name, Resource Group, Type, and Tags within the Subscription.

Sample Output:

Command:

Get-AzureRmVM  -Name  "vm_name" -ResourceGroupName "rg_name" `
| Select-Object -Property Name, ResourceGroupName, Type, Tags

It returns the properties of Name, Resource Group, Type, and Tags of a select Azure VM.

Example:

Get-AzureRmVM  -Name "CloudOpsVM" -ResourceGroupName "Cloud-Operations" `
| Select-Object -Property Name, ResourceGroupName, Type, Tags

Output:

Command:

$VM = get-azvm -Name  "vm_name" -ResourceGroupName "rg_name"

Example:

$VM = get-azvm -Name "CloudOpsVM" -ResourceGroupName "Cloud-Operations"

It will not return any output. Get and Store Tags to a Variable:

$Tags = $VM.Tags

It will not return any output. Add Tags you want the set:

$Tags += @{Environment="TST";ApplicationName="N/A"}

Apply Tags for Azure VM:

Set-AzResource `
-Name $VM.Name `
-ResourceGroupName $VM.ResourceGroupName `
-ResourceType $VM.Type `
-Tags $Tags

Output:

To Verify the applied tags use the following command

Get-AzureRmVM  -Name  "vm_name" -ResourceGroupName "rg_name" `
| Select-Object -Property Name, ResourceGroupName, Type, Tags

Example:

Get-AzureRmVM  -Name "CloudOpsVM" -ResourceGroupName "Cloud-Operations" `
| Select-Object -Property Name, ResourceGroupName, Type, Tags

Output:


Last Updated : 30 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads