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.
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.
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!
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
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
To remove a tag category:
Remove-CISTagCategory -Name Category_Name
To remove a tag:
Remove-CISTag -Name tag_name
- 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!
=== END ===