Working with PowerCLI and Tags

Hi all,

I am building up a bunch of VMs for some testing and I need to put tags on all of them.  I sometimes do that manually when there is one VM but using PowerCLI it is much easier when you have lots of VMs.  I have heard that PowerCLI and working with tags does not scale.  If you want to tag a few hundred VMs it won’t work.  I have not tested this but I have heard it in a few places.  So when I saw Kyle’s article the other day about a new way to PowerCLI and tag that does scale I thought I should use it.  Not that I need the scale but it would be good to know.

So lets get started.

Setup

First we need to download the new module - which is not in PowerShell Gallery unfortunately, but can be found here.

The use the green download button and select Download ZIP.

Once downloaded, extract the zip, and change into the modules folder. The folder we need to copy out is seen below.

Now where we copy this too is interesting.  Kyle gives you two choices of where but they don’t work for me. I use the environment set command to see where my PSModulePath points.

C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

So lets copy the VMware.Community.CISTag folder to the Modules folder in our Windows PSModule path.

So we need to test if this works!

Test Time

We need to connect to our vCenter - and yes, we do need to be somewhat modern in our virtual infrastructure - so vCenter 6.0 or newer, and PowerCLI 6.5.3 or newer.

Connect-VIServer -Server server.domain.ca

Connect-CISServer -Server server.domain.ca

Get-CISTagAssignment

And as a result you should see all your tags. This confirms things are working (if you had tags to start?)!

Creating Tags / Categories

Now we need create tag categories and tags.

New-CISTagCategory -Name FTest -Description “Test Category” -Cardinality MULTIPLE

New-CISTag -Name AppX -Category FTest -Description “Test Tag”

Now lets use this info

To assign a tag to a VM:

New-CISTagAssignment -tag tag_Name -Entity VM_Name

To assign a tag to several VMs:

New-CISTagAssignment -tag tag_Name -Entity VM_Name, VM_Name

To remove a tag from a VM:

Remove-CISTagAssignment -tag tag_Name -Entity VM_Name

Cleaning Up

To remove a tag category:

Remove-CISTagCategory -Name Category_Name

To remove a tag:

Remove-CISTag -Name tag_name

Updates

  • 6/21/19 - the release of PowerCLI today has much improved tag capability.
  • 6/14/19 - this article might be helpful too.
  • 12/20/18 - added the tidbit on how you can add a tag to multiple VMs.
  • 12/20/18 - published.

Hope that this helps everyone!

Michael

=== END ===

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.