Where are virtual machine templates located ? datastore, folder, vmtx file

I was doing some host upgrades today, and had to migrate some stuff from one place to another. I had to also manually re register templates while doing this. So in order not to lose too much time on finding where are my templates in clusters i wrote myself this tiny line which helps in this situation.

foreach($vmhost in get-cluster 'your_cluster'|get-vmhost){get-template -Location $vmhost | select name,@{n='VMHOST';e={$vmhost.name}},@{n='VMTX';e={$_.extensiondata.config.files.VmPathName}}}

Name           VMHOST           VMTX
----           ------           ----
Win_Template   host1.local      [DS01] TEMPLATE_win/Win_Template.vmtx
Win7_Template  host2.local      [DS02] TEMPLATE_win7/Win7_Template.vmtx

Within VMTX property you will see the datastore name [datastore_name] then the directory in which the vmtx resides, and then the vmtx file name. There is not much i guess to explain in this short line. First i take all vmhosts in specific cluster, then i get list of templates for each host and display its name, vmhost name and the vmpathname.

Tiny, but helpful 😉