Is it possible to use PowerCLI New-VM to create a VM from a template that resides in another vCenter? I have 2 VCSAs, the template lives in VCSA-1 and I'm attempting to deploy the VM to VCSA-2. 2. When using the Web Client, i can deploy VM's from that template to either VCSA, but i'm having problems doing this via PowerCLI. I want to avoid having redundant templates in both locations.
Not sure if it works with the New-VM cmdlet, but when it works via the Web Client, there must be an API method.
Perhaps an occasion to give the latest Code Capture a go.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Wow, this code capture looks great, unfortunately i don't have a lab to run it on
I'm also wondering if there's a way to leverage the fact that these vCenters are in linked mode.
Can you give it a try with this code?
$vc2 = 'vc2'
$templateName = 'Template'
$esxName = 'MyEsx'
$dsName = 'MyDS'
$folderName = 'TestVM'
$rpName = 'Resources'
$temp = Get-Template -Name $templateName -Server $vc1
$esx = Get-VMHost -Name $esxName -Server $vc2
$ds = Get-Datastore -Name $dsName -Server $vc2
$folder = Get-Folder -Name $folderName -Server $vc2
$rp = Get-Cluster -VMHost $esx -Server $vc2 | Get-ResourcePool -Name $rpName -Server $vc2
$spec = New-Object VMware.Vim.VirtualMachineCloneSpec
$spec.Location = New-Object VMware.Vim.VirtualMachineRelocateSpec
$spec.Location.Datastore = $ds.ExtensionData.MoRef
$spec.Location.Folder = $folder.ExtensionData.MoRef
$spec.Location.Host = $esx.ExtensionData.MoRef
$spec.Location.Pool = $rp.ExtensionData.MoRef
$temp.ExtensionData.CloneVM($folder.ExtensionData.MoRef, 'NewVM', $spec)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference