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
$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