VMware Cloud Community
Sam1230
Enthusiast
Enthusiast
Jump to solution

New-VM on linked vCenter HCI

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

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Have you looked at Content Libraries?

They can sync content between sites


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

View solution in original post

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Which vSphere and PowerCLI version are you using?


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

Reply
0 Kudos
Sam1230
Enthusiast
Enthusiast
Jump to solution

vSphere = version 6.7.0.42000

PowerCLI =

Version         Name                              

-------         ----                              

6.7.0.11233116  VMware.DeployAutomation           

6.7.0.11233116  VMware.ImageBuilder               

11.5.0.14912921 VMware.PowerCLI                   

6.7.0.14898114  VMware.Vim                        

11.5.0.14898113 VMware.VimAutomation.Cis.Core     

11.0.0.10379994 VMware.VimAutomation.Cloud        

11.5.0.14898112 VMware.VimAutomation.Common       

11.5.0.14899560 VMware.VimAutomation.Core         

11.5.0.14900247 VMware.VimAutomation.Hcx          

7.10.0.14653756 VMware.VimAutomation.HorizonView  

11.3.0.13990093 VMware.VimAutomation.License      

11.5.0.14900141 VMware.VimAutomation.Nsxt         

11.5.0.14898111 VMware.VimAutomation.Sdk          

11.0.0.10380515 VMware.VimAutomation.Security     

11.5.0.14899557 VMware.VimAutomation.Srm          

11.5.0.14901686 VMware.VimAutomation.Storage      

1.3.0.0         VMware.VimAutomation.StorageUtility

11.2.0.12483615 VMware.VimAutomation.Vds          

11.5.0.14912923 VMware.VimAutomation.Vmc          

10.0.0.7893921  VMware.VimAutomation.vROps        

6.5.1.7862888   VMware.VumAutomation

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The solution suggested in Re: PowerCLI New-VM with vCenters in linked mode seems to imply that the Template and OSCustomizationSpec need to be in the target VC


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

Reply
0 Kudos
Sam1230
Enthusiast
Enthusiast
Jump to solution

Hi.

Thanks for you response.

It does work if the templates are in the target VC - however my organisation has multiple vCenters in linked mode so it will be more difficult to maintain each pair of templates and OS Custom spec on each VC.

Is there a way to deploy template from one VC to another using PowerCLI? As how it works on the GUI client.

Thanks

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Have you looked at Content Libraries?

They can sync content between sites


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

Reply
0 Kudos
Sam1230
Enthusiast
Enthusiast
Jump to solution

Thank you. I have now implemented content-libraries in the environment using one vCenter as the publisher and the rest as subscribers.

Reply
0 Kudos