I am creating a new VM with P-CLI. The VM should be stored in a datastore cluster. I get the following error message:
Script:
PowerCLI C:\> Y:\Skripte\PS+PowerCLI\Test\ExportVC-Info\TestDatastoreCluster.ps1
DatastoreCluster: Verwaltung
New-VM : 12.01.2018 08:17:19 New-VM
Required property datastore is missing from data object of type VirtualMachineRelocateSpecDiskLocator
while parsing serialized DataObject of type vim.vm.RelocateSpec.DiskLocator
at line 1, column 1077
while parsing property "disk" of static type ArrayOfVirtualMachineRelocateSpecDiskLocator
while parsing serialized DataObject of type vim.vm.RelocateSpec
at line 1, column 983
while parsing property "location" of static type VirtualMachineRelocateSpec
while parsing serialized DataObject of type vim.vm.CloneSpec
at line 1, column 972
while parsing property "cloneSpec" of static type VirtualMachineCloneSpec
while parsing serialized DataObject of type vim.storageDrs.StoragePlacementSpec
at line 1, column 277
while parsing call information for method RecommendDatastores
at line 1, column 171
while parsing SOAP body
at line 1, column 64
while parsing SOAP envelope
at line 1, column 0
while parsing HTTP request for method recommendDatastores
on object of type vim.StorageResourceManager
at line 1, column 0
At Y:\Skripte\PS+PowerCLI\Test\ExportVC-Info\TestDatastoreCluster.ps1:27 char:5
+ New-VM -Name $VMName -VMHost $VM_Cluster -Template $NameTemplate -Location $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-VM], InvalidRequest
+ FullyQualifiedErrorId : Client20_VmServiceImpl_ApplySdrsRecommendation_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
-- Output --
DatastoreCluster: Verwaltung
New-VM : 12.01.2018 08:17:19 New-VM
Required property datastore is missing from data object of type VirtualMachineRelocateSpecDiskLocator
while parsing serialized DataObject of type vim.vm.RelocateSpec.DiskLocator
at line 1, column 1077
while parsing property "disk" of static type ArrayOfVirtualMachineRelocateSpecDiskLocator
while parsing serialized DataObject of type vim.vm.RelocateSpec
at line 1, column 983
while parsing property "location" of static type VirtualMachineRelocateSpec
while parsing serialized DataObject of type vim.vm.CloneSpec
at line 1, column 972
while parsing property "cloneSpec" of static type VirtualMachineCloneSpec
while parsing serialized DataObject of type vim.storageDrs.StoragePlacementSpec
at line 1, column 277
while parsing call information for method RecommendDatastores
at line 1, column 171
while parsing SOAP body
at line 1, column 64
while parsing SOAP envelope
at line 1, column 0
while parsing HTTP request for method recommendDatastores
on object of type vim.StorageResourceManager
at line 1, column 0
At Y:\Skripte\PS+PowerCLI\Test\ExportVC-Info\TestDatastoreCluster.ps1:27 char:5
+ New-VM -Name $VMName -VMHost $VM_Cluster -Template $NameTemplate -Location $ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-VM], InvalidRequest
+ FullyQualifiedErrorId : Client20_VmServiceImpl_ApplySdrsRecommendation_ViError,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
Anone a Idea?
Sorry, sorry. I have twice the error 😞
# Path to CSV-Source
$vms = Import-CSV "C:\Users\adm.t.heise\Documents\My_PowerShell\NewVM\NewDebian.csv" -Delimiter ";"
foreach ($vm in $vms){
#-- Assign Variables
$NameTemplate = Get-Template -Name $vm.Name_Template
$VM_Cluster = Get-Cluster $vm.Cluster | Get-VMHost -State Connected | Get-Random
$DS_Cluster = Get-DatastoreCluster -Name Verwaltung
#-- Variables of csv
$VMName = $vm.Name
$LocationFolder = $vm.Location_Folder
$VLAN = $vm.VLAN
$vCPU = $vm.vCPU
$vMemory = $vm.Memory
$vIp = $vm.IP
$vNetmask = $vm.Netmask
$vGateway = $vm.Gateway
$vFQDN = $vm.FQDN
$vDNSName = $vm.DNSName
Write-Host "DatastoreCluster: $DS_Cluster"
#-- Where the VM gets built
New-VM -Name $VMName -VMHost $VM_Cluster -Template $NameTemplate -Location $LocFolder -StorageFormat Thin -Datastore $DS_Cluster
}
And which PowerCLI version are you using?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Vcenter 6.5 / ESXi-Host 6.0
VMware PowerCLI 6.5 Release 1 build 4624819
I'm afraid that is a known issue, and unfortunately there hasn't been a fix in the later builds (currently we are at 6.5.4).
One bypass, where you also use SDRS to pick the most optimal datastore, is given in Re: Move-VM to datastore cluster with DiskStorageFlag throws error.
Another, not-SDRS based solution is to randomly pick a datastore from the datastorecluster
New-VM -Name NewVM -Template Template -VMHost esx1 -DiskStorageFormat Thin -Datastore (Get-DatastoreCluster -Name DEVDSC | Get-Datastore | Get-Random)
or a bit more advanced based on the available freespace
New-VM -Name NewVM -Template Template -VMHost esx1 -DiskStorageFormat Thin `
-Datastore (Get-DatastoreCluster -Name DSC | Get-Datastore | Sort-Object -Property FreeSpaceGB -Descending | Select -First 1)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
thanks for your prompt replay. I had already feared that it is a bug. But the workaround is a good idea.
best regards
At the moment the cmdlet doesn't support folder paths I'm afraid.
But you can use the Get-FolderByPath function from my Folder By Path post.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello,
Do we know if this issue has been resolved in the latest releases? Tried on 11.0 and still seemed to be the same issue, but wondering if 11.4/5 has fixed it.
Cheers,
Sam
That's strange because this was fixed in 11.0 afaik.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference