Skip to content

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

4 thoughts on “vSphere 5.5 - Managing Tags with PowerCLI”

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

  2. 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 Reply

Your email address will not be published. Required fields are marked *