vSphere 5.5 – Managing Tags with PowerCLI

With the new release of vSphere PowerCLI 5.5 VMware made the tagging Feature (introduced in vSphere 5.1) scriptable. The new cmdlets are working with vCenter 5.1 and vCenter 5.5. They allow you to assign tags to objects and to search for objects based on their tags. Unfortunately there is no cmdlet to create tags at the moment. The feature is still not available within the API.

New Tag related cmdlets in vSphere 5.5:

  • Get-Tag – retrieves the tag assignments of objects.
  • New-TagAssignment – assigns a tag to the specified object.
  • Remove-TagAssignment – removes a tag from the specified object.

Download: vSphere PowerCLI 5.5

Tag a virtual machine:

Get-VM VM1 | New-TagAssignment -Tag Sales

or:

$tag = Get-Tag "Sales"
Get-VM VM1 | New-TagAssignment -Tag $tag

Get objects tagged within a specific category:

Get-TagAssignment -Category "Cost Centre"

Get tags from a specific object:

Get-TagAssignment -Entity VM1

Remove tags from a specific object:

Get-VM VM1 |Get-TagAssignment |Remove-TagAssignment
  1. Thank you – I want to know how to set a Tag on a VM that have multiple TAG (or Category)

  2. This definitely looks helpful. Is similar functionality made available via vSphere Web service APIs (SOAP services) and SDK ? Particularly “get-tagassignment -entity VM1″ functionality ?

  3. Hi, thanks this is helpfull. I’m also wondering, is there a way to create tags with powerCLI? Cause I have to make a couple hundred, so scripting this would be nice :wink:

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>