Queue Deflation
I’m rather red-faced right now. I chimed in with a reply in the VMTN VMware vSphere PowerCLI forum and promptly got schooled.Which is great; these things should happen.
Where’s the Template?
In this thread, VMTN Communities member denjoh44 asked how one would obtain a list of templates along with the name of the vSphere hosts on which they reside.I haven’t had the need to do this myself, but I wanted to give it a shot. I fired up PowerShell ISE and plugged away:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Templates = @() | |
$Hosts = Get-VMHost | |
foreach ($h in $hosts) { | |
$HostTemplates = Get-Template -Location $h | |
foreach ($t in $HostTemplates) { | |
$TemplateInfo = New-Object PSObject | |
$TemplateInfo | Add-Member -MemberType NoteProperty Name -Value $t.Name | |
$TemplateInfo | Add-Member -MemberType NoteProperty Host -Value $h.Name | |
$Templates += $TemplateInfo | |
} | |
} | |
$Templates |
I See Your 12 Lines and…
It wasn’t long after that I revisited the thread only to find a much more elegant solution posted by Christophe Calvet:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-Template | | |
Select-Object Name, @{N="Host"; E={(Get-View $_.HostId).Name}} | | |
Format-Table -AutoSize |
Time to Learn
Brian Graf has a 3-part blog series on Get-View which I’ve seen before and marked for reading in more detail “later.” If you are interested in learning more about Get-View, start here:- Get-View Part 1: Introduction
- Get-View Part 2: Views and Extension Data
- Get-View Part 3: Performance Impact