Forum Discussion
Any idea on how to query Get-AzTag using both Name & Resource ID?
- May 06, 2022
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-AzVMCheers,
Lain
Hi
Since the VM has 3 tags i just want to filter the 1st tag without doing a loop. Is that even possible?
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
- Alan2022May 06, 2022Iron ContributorLainRobertson
Hi
Thanks for pointing out the Get-AzResource. This is the result that i want.
Keep up the good job.
$result = (Get-AzResource -Name VM001).Tags
$result['Tag01']