How to Get Azure Virtual Machine Tags with PowerShell

In this Azure PowerShell blog post, we are going to show how to retrieve Azure Virtual Machine tags using the Az PowerShell module.

The Az PowerShell module allows us to deploy, manage and reserve almost any information about the deployment using PowerShell.


The Get-Aztag cmdlet allows us to retrieve all the tags that are associated with any Azure resource.

In the following code, we use it with Azure VMs only.

The first line of code gets all the Azure Virtual Machines in the subscription and saves them to a variable.

The middle section of the code uses a foreach loop to loop over each VM and output the Tags associated with each VM.

$resources = Get-AzResource | Where-Object { $_.Type -eq "Microsoft.Compute/virtualMachines" }

foreach ($item in $resources) {

   get-aztag -ResourceId  $item.ResourceId

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.