How to get the value of a virtual machine that has a tag=PURPOSE using PowerShell?

Martin Thong 60 Reputation points
2023-09-27T04:38:04.0866667+00:00
$vm = Get-AzVM # Get all the vms
$vm
$vm.Tags # See all the Tags key value pairs.
$vm.Tags['PURPOSE'] # The key=PURPOSE is there but it does not give me its value.


Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,033 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. deherman-MSFT 38,021 Reputation points Microsoft Employee Moderator
    2023-10-02T16:29:07.6733333+00:00

    @Martin Thong

    I understand you have some VMs with the tag=PURPOSE. You are wanting to get a list of these VMs and also the value of the PURPOSE tag. Please let me know if I am misunderstanding the issue.

    Please try this command and see if it works for you. During my testing it outputted the expected results.

    Get-AzResource -ResourceType Microsoft.Compute/virtualMachines -TagName "PURPOSE" | Format-Table Name, @{Name='PURPOSE'; Expression={$_.Tags['PURPOSE']}} 
    

    Hope this help! Let me know if you still have questions.


    If you still have questions, please let us know in the "comments" and we would be happy to help you. Comment is the fastest way of notifying the experts.

    If the answer has been helpful, we appreciate hearing from you and would love to help others who may have the same question. Accepting answers helps increase visibility of this question for other members of the Microsoft Q&A community.

    Thank you for helping to improve Microsoft Q&A! User's image

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.