Ladies and Gents,
I know I should know this but I am feeling slightly the worse for wear this morning and cannot get my head around this simple problem.
How do I retrieve the VM Host name of a template?
From a VM it is as easy as:
get-vm MY-VM | get-vmhost
but the following does not work
get-template MY-TEMPLATE | get-vmhost
There just does not appear to be a Host property on a template object or rather I cannot seem to get my mind to work out which property to hunt down. ( This is probably due to the small amount of blood in my alcohol stream ).
Any quick help would be greatly appreciated.
Regards
Steve
A template is nothing more then a "special" virtual machine.
Unfortunately the Get-VMHost cmdlet doesn't seem to know how to handle this type of virtual machine.
So you have 2 choices:
1) convert the template to a virtual machine and then use the Get-VM | Get-VMHost method
2) find the host with the SDK VirtualMachine object
This is a sample script for the 2nd method
Get-Template | Select @{Name = "Template"; Expression = {$_.Name}}, @{Name = "Host"; Expression = {(Get-View (Get-Template -Name $_.Name | Get-View).Summary.Runtime.Host).Name}}
A 1 1/2 liner but then it's Friday after all
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
A template is nothing more then a "special" virtual machine.
Unfortunately the Get-VMHost cmdlet doesn't seem to know how to handle this type of virtual machine.
So you have 2 choices:
1) convert the template to a virtual machine and then use the Get-VM | Get-VMHost method
2) find the host with the SDK VirtualMachine object
This is a sample script for the 2nd method
Get-Template | Select @{Name = "Template"; Expression = {$_.Name}}, @{Name = "Host"; Expression = {(Get-View (Get-Template -Name $_.Name | Get-View).Summary.Runtime.Host).Name}}
A 1 1/2 liner but then it's Friday after all
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD,
Thank you for this code it works perfectly.
Carter - (or anyone else from VMware that may be reading this) - Any chance of getting this altered in the next realease so that GET-TEMPLATE | GET-VMHOST works as with GET-VM | GET-VMHOST?
Regards
Brucky