VivaLaRobo
Contributor
Contributor

How to return tag of a specific VM

Hello,

I am trying to return the value of the tag for a specific VM

Using something like

'get-vm WIN-17-07 | get-tagassignment | select tag'

will return the Category name + the Tag name such as:

'jenkinsInstance/Jenkins'

but I want it to return the Description field which is where I have the URL saved

if I do 'get-tag' I see all of the tags, including the one I want to use, plus it's Description, but I can't get it to return the Description based on a VM name that I give it.

I basically want to run:

'get-tag | Where VM-Name -eq "WIN-17-07" | Select-Object Description'

But I can't seem to because "get-tag" only returns the tag name, category, and description so I can't specify which VM name to get the tag from.

How do i do this?

0 Kudos
1 Reply
LucD
Leadership
Leadership

Can't you just do

Get-VM -Name MyVM | Get-TagAssignment |

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

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

   @{N='Description';E={$_.Tag.Description}}

or

Get-TagAssignment |

where{$_.Entity.Name -eq 'MyVM'} |

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

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

   @{N='Description';E={$_.Tag.Description}}


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

0 Kudos