New-VM on linked vCenter HCI

This post was originally published on this site

Hi.

 

There are 2 vCenters on HCI platform in linked mode.

 

vCenter1

vCenter2

 

Templates and Customization specs resides on vCenter1.

 

Using PowerCLI, I am trying to deploy a VM from the template to vCenter2.

 

I can do this successfully if the templates are on vCenter2 however I must keep them on vCenter1.

 

I have tried amending my script as follows:

 

$sourceVCenter = ‘vCenter1’

$destVCenter =  ‘vCenter2’

 

$vmName = ‘VMTest1’

$templateName = ‘WindowsServer2016’

$clusterName = ‘Cluster-01’

$customisationName = ‘WindowsServer’

$datastoreName = ‘VSAN-01’

$folderName = ‘Temporary’

 

 

 

New-VM -Name $vmName -Template (Get-Template  $templateName -Server $sourceVCenter) -ResourcePool (Get-Cluster $clusterName -Server $destVCenter) -OSCustomizationSpec (Get-OSCustomizationSpec $customisationName -Server $sourceVCenter) -Datastore (Get-Datastore $datastoreName -Server $destVCenter) -Location $(Get-Folder $folderName -Server $destVCenter)

 

However I am getting the error:

New-VM Index was out of range. Must be non-negative and less than the size of the collection.

 

I have connected to both vCenters with connect-viserver.

 

I have also tried adding -Server $destVCenter at the end of the above script. Still no joy.

 

What am I doing wrong?

 

Thanks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.