Hi Tirou,
a PowerCLI template object misses a lot of features that a VM object has. So the easiest thing is to change the template into a VM, clone the VM and change the old and new VM's back into templates. Something like:
$Template = "MyTemplate"
$Datastore = "MyDatastore"
# Change to template to a VM
$vm = Set-Template -Template $Template -ToVM
#Create a list of datastores the template uses
$Datastores = @()
$vm.DatastoreIdList | ForEach-Object {
$Datastores += (Get-View -Id $_).Name
}
# Only copy the template if the datastore is not already used by the template
if ($Datastores -notcontains $Datastore) {
$NewVM = New-VM -Name "$Template-$Datastore" -VMHost $vm.VMHost -VM $vm -Datastore $Datastore -Confirm:$false
}
#Change the VM's back to templates
$OldTemplate = Set-VM -VM $vm -ToTemplate
$NewTemplate = Set-VM -VM $NewVM -ToTemplate
Regards, Robert
Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition