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.

Aztag

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
}





Posted

in

,

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

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