Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Microsoft Azure – Assigning Tags to a Azure VM

  • Last Updated : 29 Dec, 2021

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 "r

me"

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:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!