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 😉

Advertisements

System Center Orchestrator and opened sessions from scripts using PowerCLI

Very quick note to myself (if i will ever need to use system center orchestrator) and internet ;). I was helping out today one person on #PowerCLI. His scripts that were being fired up in system center orchestrator did not quit properly. We first wrote quite a long workaround 😉 but after an hour i asked that person to disconnect in different way.
Instead of :
disconnect-viserver -Confirm:$false
i recommended to use:
disconnect-viserver -Confirm:0

And it helped, his scripts no longer exit with errors, and all script sessions are closed after script is finished.