PowerCLI-Example-Scripts
PowerCLI-Example-Scripts copied to clipboard
New-HVPool : Failed to create Pool with error: TESTINGTEMPLATE not exists in datacenter: [/contoso]
Horizon connection server 7.13 Powershell 5.1.18362.1171 VMware.HV.Helper 1.3.1 VMware.Vim 7.0.1.17531376 VMware.VimAutomation.Cis.Core 12.2.0.17531611 VMware.VimAutomation.Common 12.2.0.17531244 VMware.VimAutomation.Core 12.2.0.17531987 VMware.VimAutomation.HorizonView 12.2.0.17463427 VMware.VimAutomation.Sdk 12.2.0.17531155
I found that when you use Get-HvPoolSpec, the returned 'Datacenter' always has a leading forward slash / When you attempt to make a new pool using the same datacenter name and template, you will get a powershell error.
This is because the if condition checking to see if the datacenter exists is assuming you are not passing your datacenter with a leading / and inserts one for you
if (! ($VmTemplateInfo.Path -like "/$dataCenter/*")) { throw "$template not exists in datacenter: [$dataCenter]" }
Additionally, other values from keys in the VirtualCenterProvisioningData properties are expecting that you do provide a leading / (vmFolder, hostOrCluster, resourcePool)
Received from Get-HvPoolSpec: "VirtualCenterProvisioningData": { "Template": TESTINGTEMPLATE "ParentVm": null, "Snapshot": null, "Datacenter": "/contoso", "vmFolder": "/contoso/vm/View Pools", "hostOrCluster": "/contoso/host/contosohost00", "resourcePool": "/contoso/host/contosohost00/Resources" },
Expected result: Should be able to reference properties from Get-HvPoolSpec for use in New-HvPool
Actual result: Datacenter property returned by Get-HvPoolSpec will be filtered out when used in New-HvPool and result in an error.
Proposed Fix:
In New-HvPool, change this line:
if (! ($VmTemplateInfo.Path -like "/$dataCenter/*")) { throw "$template not exists in datacenter: [$dataCenter]" }
To this:
if (! ($VmTemplateInfo.Path -like "$dataCenter/*")) { throw "$template not exists in datacenter: [$dataCenter]" }