Forum Discussion

Alan2022's avatar
Alan2022
Iron Contributor
May 05, 2022
Solved

Any idea on how to query Get-AzTag using both Name & Resource ID?

Any idea on how to query Get-AzTag using both Name & Resource ID? Thanks.   Example. Get-AzTag -Name TagName -ResourceId $vm.Id | Select -ExpandProperty properties
  • LainRobertson's avatar
    LainRobertson
    May 06, 2022

    Alan2022 

     

    I'm not sure I understand what it is you're trying to achieve.

     

    Are you trying to retrieve tag statistics, which is what you get from Get-AzTag, or are you trying to find virtual machines by tag name, which is what Get-AzResource/Get-AzVM helps with?

     

    Or is it some other scenario I'm not guessing?

     

    I'm going to make an uninformed guess as to what you're trying to do here and then provide an example. Maybe it will help. Otherwise, let us know exactly what it is you're trying to achieve.

     

    I'm going to provide a command that demonstrates how you can fetch Azure virtual machines by tag name and value (which is what I'm assuming you're trying to do) without having to enumerate all the Azure virtual machines and then inspect them client-side.

     

     

    Get-AzResource -TagName "MyTagName" -TagValue "SomeTagValue" -ResourceType "Microsoft.Compute/virtualMachines" | Get-AzVM

     

     

    Cheers,

    Lain

Resources