VMware Cloud Community
MRoushdy
Hot Shot
Hot Shot
Jump to solution

Get VM + Assigned Tag

Hi,

I need to get VM and the Tag(s) assigned to it, but couldn't get a correct result, could you please review this simple script, or give me another idea.

$getvm = get-vm

Get-vm | Get-TagAssignment | select -Property @{N="VM Name";E={$getvm}} , Tag

Thanks,

vEXPERT - VCAP-DCV - Blog: arabitnetwork.com | YouTube: youtube.com/c/MohamedRoushdy
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-VM |

Select Name,@{N='Tags';E={(Get-TagAssignment -Entity $_).Tag -join '|'}}

Or if you only want to see VMs that have a Tag assigned

Get-TagAssignment |

Select @{N='VM';E={$_.Entity.Name}},Tag


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try like this

Get-VM |

Select Name,@{N='Tags';E={(Get-TagAssignment -Entity $_).Tag -join '|'}}

Or if you only want to see VMs that have a Tag assigned

Get-TagAssignment |

Select @{N='VM';E={$_.Entity.Name}},Tag


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
MRoushdy
Hot Shot
Hot Shot
Jump to solution

Thanks LuCD,

The second command needs a little modification in the suffix to be like this:

Get-VM | Get-TagAssignment | Select @{N='VM';E={$_.Entity.Name}},Tag

Good day,

vEXPERT - VCAP-DCV - Blog: arabitnetwork.com | YouTube: youtube.com/c/MohamedRoushdy
0 Kudos