VMware Cloud Community
tdubb123
Expert
Expert

new-template on cluster A

how do I specify cloning a new vm from a template based on certain location?

I have different datacenters and clusters and have templates based on their physical locations (cluster)

new-vm -Name xxx -vmhost xxx -Template yyyy

but it says I have multiple template with same names.

Do I need to have each template in each location with unique names?

0 Kudos
4 Replies
Zsoldier
Expert
Expert

You could do something like this:

New-VM -Name xxx -vmhost xxx -Template (get-cluster xxx | get-template yyyy)

Or:

New-VM -Name xxx -vmhost xxx -Template (get-datacenter qqq | get-cluster zzz | get-template yyyy)

That should be the idea anyway.  It might be easiest to append or prefix the template names w/ location|cluster|orwhateveruniqueinfo.

Message was edited by: Zsoldier

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos
tdubb123
Expert
Expert

I am getting this

> Get-Cluster  "xxx"  | Get-Template
Get-Template : 1/10/2012 10:11:01 PM    Get-Template        ClusterImpl is not
a valid location type for Get-Template.
At line:1 char:38
+ Get-Cluster  "xxx"  | Get-Template <<<<
    + CategoryInfo          : InvalidArgument: (ESX PA:ClusterImpl) [Get-Templ
   ate], VimException
    + FullyQualifiedErrorId : Core_ContainerCmdletBase_GetValidLocations_Inval
   idLocation,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetTemplate
Get-Template : 1/10/2012 10:11:01 PM    Get-Template        The values specifie
d for the Location parmeter are not valid for the Get-Template cmdlet.
At line:1 char:38
+ Get-Cluster  "xxx"  | Get-Template <<<<
    + CategoryInfo          : InvalidArgument: (VMware.VimAutom...y.VIContaine
   r[]:VIContainer[]) [Get-Template], VimException
    + FullyQualifiedErrorId : Core_ContainerCmdletBase_TryValidateParameterLis
   t_AllLocationsAreInvalid,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetT
  emplate
0 Kudos
LucD
Leadership
Leadership

We had mentions of this problem before.

Although the documentation states that Location can be a datacenter, cluster or folder, the cmdlet only seems to accept a datacenter or folder.

Which is logical I guess, templates are visible in the VMs and Templates view in the vSphere client, and there you only have datacenters and folders.

So I suspect this is a documentation error.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership

There is a way to get the templates that are linked to a cluster.

Something like this

$morefs = Get-Cluster MyCluster | Get-VMHost | %{$_.ExtensionData.MoRef}

Get-Template | where {$morefs -contains $_.ExtensionData.Runtime.Host}


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos