Get vSphere Tags out of a category with PowerCLI

Introduction to vSphere Tags

Using vSphere tags in your VMware environment is no longer a secret. It gives you flexibility, easier management and control of your virtual machines.

If you want to see how to use vSphere Tags with Veeam check out my article here: Using VM Tags with vSphere and Veeam Backup & Replication

When it comes to backup virtual machines via vSphere Tags you will most likely force the strategy to give every single virtual machine a tag.

There is the famous “no backup” tag for virtual machines which are excluded from backup. Furthermore, all the other vSphere tags are necessary to declare your SLA policies.

To ensure that your tagging strategy is resilient, you will need to tag every single virtual machine in your environment. But what if your environment is in undergoing change and virtual machines are deployed and deleted heavily. You will moste likely have any kind of monitoring in place such as VeeamONE to monitor if all your virtual machines have a vSphere tag in place.

Today I want to show you a way on how to achieve this kind of monitoring with a simple PowerCLI script.

What does this script do with your vSphere Tags?

The script does the following:

  • It connects to your vCenter Server
  • It checks all virtual machines if they have a vSphere Tag out a category you decide
  • When it finds virtual machines with no tags out of the desired category it writes an output
  • The outputs gets send via E-Mail to an email address you provide
  • It checks the output path for old files and deletes them if they are older than X days

My recommendation is to setup a scheduled task which runs once or twice a day to check your environment.

The script:

Please keep in mind, that I will maintain this script on github not in this blog post: Here is the link to the script on github

How to set it up for your environment

Basically, you simply need to add all the relevant information in the variables which I framed in red in the below screenshot.

vSphere Tags VMware

  • the path where you want to save the outputs
  • the e-mail settings
  • your vSphere credentials and connection
  • your desired tag category

As always, thanks for reading and have a nice day !

If you encounter errors or if you want to share feedback, don’t hesitate to do here with a comment or on github !

About Falko Banaszak

Falko is a consultant based in Germany working for SVA GmbH. He has a strong focus on virtualization, data backup, disaster recovery infrastructures and a passion for Microsoft 365 & storage systems. He´s a VMware vExpert & Veeam user group leader in Germany. VCP-DCV, VMCE, VMCA.

Check Also

Veeam Live 2020

Get ready for Veeam LIVE 2020 !

Veeam LIVE 2020 is going to take place on the 20th of October 2020 ! …

Leave a Reply

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