Home > Blogs > VMware PowerCLI Blog

Using Tags with PowerCLI

The Tagging feature was introduced in vCenter Server 5.1 where custom defined tags can be categorized and added to any of your inventory objects in your environment.

Tags can be quickly searched on and retrieved quickly. Multiple unique tags can be used on the same inventory object creating granular metadata that can easily be grouped and search on.

As an example this is helpful for looking for all VMs tagged against a particular project or placing all departmental objects into groups, IE HR requiring not just there VMs but networking and datastores used as well, This all benefits the administrator by simplifying management and making information more easily available.


In PowerCLI 5.5 R1 we introduced some cmdlets for working with tag assignments and easily allowing multiple inventory objects to be tagged or removed from a tag in an automated fashion.

Tag Cmdlets

An initial discovery shows 4 new tag cmdlets to work with inventory objects, but don’t forget that you can also use some of the existing cmdlets with tag information as well, such as Get-VM –Tag “Gold”.



These cmdlets now have tag parameter

The following example returns all VMs with a tag of “Gold”.

Get-VM –Tag Gold

The following example returns all VMs with a tag of “Gold”.


The following example returns all tags named “MyTag”.

Get-Tag -Name MyTag

The following example returns all tags from the “MyCategory1” and “MyCategory2” categories, named “MyTag”.

Get-Tag -Category MyCategory1, MyCategory2 -Name MyTag


The following example retrieves all tag assignments for the $datastore entity that have tags from the “MyCategory” category.

$myDatastore = Get-DataStore MyDatastore

Get-TagAssignment -Entity $datastore -Category MyCategory


The following example can be used to assign the “MyTag” tag to all virtual machines whose name contains the “*myvm*” wildcard pattern.

$myTag = Get-Tag MyTag

$myVM = Get-VM ‘*myvm*’

New-TagAssignment -Tag $myTag -Entity $myVM


The following example removes all connections to tags from the specified virtual machine entity.

$myVM = Get-VM myvm

$myTagAssignment = Get-TagAssignment $myVM

Remove-TagAssignment $myTagAssignment

See them in action

In the below video we show how to use these cmdlets to easily tag some virtual machines and retrieve tag information for a number of virtual machines with PowerCLI.


This entry was posted in Reporting, Tags and tagged , on by .
Alan Renouf

About Alan Renouf

Alan Renouf is a Product Line Manager at VMware focusing on API's, SDK's and CLI's, He is responsible for providing the architects and operators of private and public cloud infrastructure with the toolkits/frameworks and command-line interfaces they require to build a fully automated software-defined datacenter. Alan is a frequent blogger at http://blogs.vmware.com/PowerCLI a book author and has a personal blog at http://virtu-al.net. You can follow Alan on twitter as @alanrenouf.

34 thoughts on “Using Tags with PowerCLI

  1. gert

    Hi alan,

    nice stuff.

    question just to clarify:
    Are tags are not stored in the vCenter Database. What is the best way to back them up??


  2. Amit

    New-TagAssignment : Cannot convert ‘System.Object[]’ to the type ‘VMware.VimAutomation.Sdk.Types.V1.VIObjectCore’ required by param
    eter ‘Entity’. Specified method is not supported.
    + New-TagAssignment -Tag $myTag -Entity <<<< $myVM
    + CategoryInfo : InvalidArgument: (:) [New-TagAssignment], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgument,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.NewTagAssignment

    when trying to execute New-TagAssignment -Tag $myTag -Entity $myVM

    any idea why?

  3. Johann Stander

    Hi Alan
    This is very helpful information on the powercli but have been trying to figure out how to provide this information to users from within the vsphere web client.
    When listing all the virtual machines under related objects within a datacenter and adding columns, you can still only add the columns from the old custom attributes which has been migrated to Tags.
    Wonder if you seen anything within web client before to show the tag associations and where assigned.

  4. Daryl Greenwood

    When will we see the ability to create, delete, and edit categories and tags using PowerCLI? We have multiple farms with thousands of VMs and we leverage automation wherever possible. One particular custom category I would like to create or modify tags in is called “Application Support Team or Queue”. The data for the tags comes from an external source. We currently populate an attribute with this data, but customers using the WEB client can not see attribute(s). Creating, deleting, and editing categories and tags is currently not possible using PowerCLI. We also have an attribute called “Created On” that shows the VM creation date that just does not seem to fit into tags very well unless I want thousands of them. We are forced to dump all types of information into the notes field for our WEB users, making it difficult to report on and maintain.

    Is there any way to stop the web converter from creating its own description (Besides changing each entry manually)?
    I do not like seeing:
    Migrated from custom attribute:Application Support Team or Queue
    Migrated from custom attribute:Application Support Team or Queue (1)
    Migrated from custom attribute:Application Support Team or Queue (2)
    I want them blank.

    The transition from attributes to tags has not been very graceful. 🙁

  5. Javier Flores

    This is great. Are there plans to make this functionality available on vMA?

  6. Pingback: Clúster de ESXi 5.5 no publica Storage Policies a vCloud Director 5.5.1 | Capítulos de una jornada hacia la nube

  7. Development

    My only blog are the readings for which they cares about above his life. You must make more thoughts. Thank you! The guy flipped around the mega tech blast while they must yell which they must be smart.

  8. maziar

    below code use CSV file to update VM’s tag
    import-csv D:\XXX.csv | ForEach-Object {
    $vmName=Get-VM $_.name
    New-TagAssignment -Tag $_.tag -Entity $vmName

  9. Pingback: Custom Attributes != vSphere Tags | virtuallyGhetto

  10. Flirty Questions to ask a girl

    tags with power

  11. Mothers Day 2016

    This was really an interesting topic and I kinda agree with what you have mentioned here!

  12. MikeJ

    Tags are a wonderful idea.. however when you do run a simple “Get-TagAssignment -Entity you get a return like this:
    Tag Entity
    — ——
    / VMNAME CustomAttribute#1 CustomAttribute#2

    and depending the custom attribute field name.. it could be before the VMNAME, this making what should be a simple script or one-liner a pain because of the searching. is there any way to get a simple dump out with powercli of the VMname and the tags that have been assigned to that VM?

  13. tRuth or dAre

    But many thanks to you, great post. interesting topics.

  14. good morning meme

    This was really an interesting topic and I kinda agree with what you have mentioned here!

  15. TimS

    Good blog .. just writing a set-tagassignment function to replace a specific tag with a different one and I am struggling to see a way of removing a specific tag.

    There seems to be a way of removing all the tags from a VM or all tags in a specific category from a VM but no way of removing a specific tag from a VM

    Any help would be appreciated

  16. lvsi

    HI vSphere SDK for Perl Utility Applications Reference

    ./vmcreate.pl –url –username root –password XXX

    Error creating VM ‘TestVM’: Host ‘ABC.XXX.XXX’ not found

    help me

  17. good dares


  18. khisu

    Hi all,

    Nice stuff. Tags are a wonderful idea…i agreeed with the solutions

  19. steven

    wow interesting topic and I really agree with what you have said and explained here!

  20. pavan

    i have BDP as tag name which i crated under tag category DEV ( aka development ) & PROD ( production ).
    now when i have to assgin VM’s i get an error as its finding duplicate tag names. how do i resolve this

  21. Pingback: VMWARE : Gestion des TAG’s sur les machines virtuelles – blog.jcabeza.fr // blog_it

  22. Tobias

    Hey there, I believe the example with the “Get-TagAssignment” example is wrong.

    It says:
    $myDatastore = Get-DataStore MyDatastore
    Get-TagAssignment -Entity $datastore -Category MyCategory

    The factual request will look for the $datastore variable but $myDatastore is supposed to be used, isn’t it?

  23. gordon grant

    I had an issue where the Get-Tag cmdlet would return an error message saying “Specified argument was out of the range of valid values”. To get around this problem use the workaround from the VMware communities forum here.



    its a very helpful blog thanks for sharing if you need any type of help regardingRand McNally GPS then in that situation visit our website and read this blog. https://www.helptechnumber.com/way-to-use-rand-mcnally-dock-removal-tool-by-rand-mcnally-support-team/

  25. Rand McNally Maps

    Thanks for sharing Nice and good blog if you need any type of help regarding Rand McNally GPS like RAND MCNALLY MAPS UPDATE, RAND MCNALLY UPDATE then in that situation visit our website. https://www.fix1st.com/gps/rand-mcnally-update/how-to-manually-update-rand-mcnally-maps/


    it’s a very informative blog thanks for sharing if you are encountering any type of issues related to Avast Antivirus like HOW TO UPDATE AVAST ANTIVIRUS then in that situation visit our website and read this blog. https://www.technically-speaking.org/antivirus/how-can-you-update-avast-antivirus/

  27. Rand McNally TND 720 Update

    Thank you for this blog if you are confronting any type of issues regarding Rand McNally Gps like Rand McNally Dock installed then in that situation visit our website. http://www.randmcnallymapsupdate.com/how-to-perform-rand-mcnally-tnd-720-update/

  28. Avira Support Number

    Thanks for the topic its very informative. Avira is the best free antivirus in the current software industry.According to its usage, its users sometimes face weird issues like error code 556,12,45,550, to solve it you need to contact the support team. They will help you get your problem solved immediately.

    Avira Support Number

  29. Upgrade Problems in Windows 10

    This blog really helped me a lot. I have read it multiple times. Please keep sharing. In case you encounter any Upgrade Problems in Windows 10, we are here to help you. Read our blog and visit our website for complete resolution: https://www.fix1st.com/microsoft/how-to-solve-windows-10-update-and-upgrade-problems/

  30. Rand McNally Truck GPS Update

    its a very innovative and Unique Article thanks for sharing. If you are Using Rand McNally Gps and you are confronting How to Update Rand McNally Truck GPS then in that situation you may visit our website and read this blog for the best solution in limited time. http://www.randmcnallyupdates.com/news-and-updates/how-to-update-rand-mcnally-truck-gps/

  31. Change Satellite Setting Garmin

    Thanks for sharing such a Wonderful post, if you are a Gamin Gps User and Sometimes you face Issues in Change Satellite Setting Garmin device , Change Satellite Setting Garmin device then in that situation you may visit our website for the Instant solutions. http://www.garminnuviupdates.com/change-satellite-settings-garmin-vivoactive-device-via-garmin-gps-update/

  32. HP Customer Care

    Nice and good blog thanks for sharing. if you are having any types of problems related to Hp Products then in that situation visit Our Website. https://www.hpcustomercares.com/


Leave a Reply

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