PowerCLI to list Template Info

We are starting to decommission the legacy VMware hosts in my work environment. Normally not a big deal or script for a task like this, but give me enough time I found a need. Templates. So you can easily find templates either using the H5 client or PowerCLI.

VM templates
Get-Template

This cmdlet displays a list of the template VMs that are in the environment, but it doesn’t say where they are located. I had a issue where a template was left on a cluster, all of the hosts were put into maintenance mode, then tried to convert the template to virtual machine. It didn’t like that, it didn’t like that at all. After some troubleshooting, and log reading, I found the template and fixed the problem. But if the cmdlet would have displayed the location information, I would have known from the beginning.

Get-Template | Select *

Using this command, it give you more information about each template. The problem is all of the information is in the form of IDs. So unless you can remember that Host-6293 is the first host in your Non-Production cluster you’ll need to find a way to convert the ID into the host name. So time to mash the keyboard to get what we need.

Get-Template | Select Name, @{N="Host";E={(Get-VMhost -id $_.HostID).Name}}

So now this displays the Name and VMhost that the template calls home. If you want to got a step further, I can add the datastore name.

Get-Template | Select Name, @{N="Host";E={(Get-VMhost -id $_.HostID).Name}}, @{N="Datastore"; E={(Get-Datastore -id $_.DatastoreIDlist).Name -join ","}} | FT -AutoSize

This will return a table with the information to see which VMhost the template is on, along with the datastore name.

-Stuart

Leave a Reply

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

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