VMware Cloud Community
lexi2code
Contributor
Contributor
Jump to solution

Powercli deploy vm from Template - specify path of template

Trying to deploy a VM from template using power cli using this:

New-VM -Name $vmname -Template $template -Datastore $datastore -ResourcePool $cluster -ErrorAction stop

The issue is I have templates with the same name in various folders in my vcenter.  When I specify the path to the template in the command above, I get "Could not find Template with name datacenter/vm/Linux8template"

Any ideas on how I could specify the path to the template in the command above?

Labels (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If that Foldername is unique, you can do

$template = Get-Folder -Name <foldername> | Get-Template -Name Linux8template 

If that is not the case, you can get the folder object by using my Get-FolderByPath function.
Once you have that you can use the Get-Template with the Location parameter

$folder = Get-FolderByPath -Path 'datacenter/<foldername>
Get-Template -Name Linux8template -Location $folder

Note that you don't specify the hidden folder 'vm' in the Path


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

View solution in original post

Reply
0 Kudos
1 Reply
LucD
Leadership
Leadership
Jump to solution

If that Foldername is unique, you can do

$template = Get-Folder -Name <foldername> | Get-Template -Name Linux8template 

If that is not the case, you can get the folder object by using my Get-FolderByPath function.
Once you have that you can use the Get-Template with the Location parameter

$folder = Get-FolderByPath -Path 'datacenter/<foldername>
Get-Template -Name Linux8template -Location $folder

Note that you don't specify the hidden folder 'vm' in the Path


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

Reply
0 Kudos