vSphere Tags

PowerCLI One-Liner to Get VM Tags

posted by Mike Nisk on Mar 29, 2016

So, here's an easy one. Sometimes you need a list of a virtual machine tags from vSphere.

Get-VM <Name of VM> | Select Name,@{N="Tags";E={((Get-TagAssignment -Entity $_ | select -ExpandProperty Tag).Name -join ",")}}



If you want to output that to a csv, then you can pipe that to Export-Csv:

Get-VM <Name of VM> | Select Name,@{N="Tags";E={((Get-TagAssignment -Entity $_ | select -ExpandProperty Tag).Name -join ",")}} | Export-Csv -NoTypeInformation c:\temp\tags.csv

Note: Optionally, you can pipe to Format-List (i.e. fl *) or even easier, pipe to Out-GridView.


That's all for now. Enjoy!


Category:PowerCLI Tags: vSphere Tags PowerCLI