PowerCLI 5.1 Release1 Move-VM Bug





While trying to write a script to move our VMs to a newly created datastore cluster I discovered a bug in PowerCLI. The issue only comes into play when trying to convert to thin provisioning. I am using PowerCLI 5.1 Release 1 build 793510.
If you run this command you get a giant trace stack:
1 |
Move-VM -VM myVMname -Datastore DatastoreClusterNAME -DiskStorageFormat Thin2GB |
Running the same command without the -DiskStorageFormat flag will work fine:
1 |
Move-VM -VM myVMname -Datastore DatastoreClusterNAME |
Also if you run the command with the thin provision flag against a datastore and not a datastore cluster it works fine as well:
1 |
Move-VM -VM myVMname -Datastore DatastoreNAME -DiskStorageFormat Thin2GB |
I posted on the VMware PowerCLI forum and it was confirmed that this was a bug.
Commenter LucD (http://www.lucd.info/) used Onyx to discover that the cmdlet fills in the RelocateSpec.disk property while the SDK Reference seems to say “RelocateSpec.disk.datastore; the fields should be unset if the user wants SDRS recommendations“. If I do the call with an empty RelocateSpec.disk property, the method works without a problem.
He also came up with this work around:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
$vmName = "MyVM" $dscName = "MyDatastoreCluster" $vm = Get-VM -Name $vmName $dsc = Get-DatastoreCluster -Name $dscName $storMgr = Get-View StorageResourceManager $storageSpec = New-Object VMware.Vim.StoragePlacementSpec $storageSpec.type = "relocate" $storageSpec.priority = "defaultPriority" $storageSpec.vm = $vm.ExtensionData.MoRef $pod = New-Object VMware.Vim.StorageDrsPodSelectionSpec $pod.storagePod = $dsc.ExtensionData.MoRef $storageSpec.podSelectionSpec += $pod $storPlacement = $storMgr.RecommendDatastores($storageSpec) $tgtDS = $storPlacement.Recommendations[0].Action[0].Destination $spec = New-Object VMware.Vim.VirtualMachineRelocateSpec $spec.datastore = $tgtDS $vm.ExtensionData.Config.Hardware.Device | where {$_ -is [VMware.Vim.VirtualDisk]} | %{ $disk = New-Object VMware.Vim.VirtualMachineRelocateSpecDiskLocator $disk.diskId = $_.Key $disk.datastore = $tgtDS $disk.diskBackingInfo = New-Object VMware.Vim.VirtualDiskFlatVer2BackingInfo $disk.diskBackingInfo.fileName = $_.Backing.FileName $disk.diskBackingInfo.datastore = $tgtDS $disk.diskBackingInfo.diskMode = "persistent" $disk.diskBackingInfo.split = $false $disk.diskBackingInfo.writeThrough = $false $disk.diskBackingInfo.thinProvisioned = $true $disk.diskBackingInfo.eagerlyScrub = $false $disk.diskBackingInfo.uuid = $_.Backing.Uuid $disk.diskBackingInfo.contentId = $_.Backing.ContentId $disk.diskBackingInfo.digestEnabled = $false $spec.disk += $disk } $vm.ExtensionData.RelocateVM_Task($spec, $null) |
This worked great to get around the issue. I will be posting soon outlining why I needed to do this 🙂




