A recent post in the community (Re: Relocate VM Harddisk) resulted in the attached workflow. In short, the Library copy of the "Relocate virtual machine disks" workflow passes the "disk" value as null to the relocateSpec. This results in all disks being placed on the same datastore. What needs to be done (and is done in the attached flow) is each disk you wish to move must be matched up to a target datastore by way of a VcVirtualMachineRelocateSpecDiskLocator. These mappings are passed into an array and that array gets assigned to the "disk" input of the relocateSpec.
Here is the key code that makes things work:
var devices = vm.config.hardware.device;
if (datastore == null){
// targetDatastore Must have a value. If no value is specified, default to the first returned disk from the vm.datastore array
targetDatastore = vm.datastore[0];
}else{
targetDatastore = datastore;
}
var dsArray = new Array(disk0DS,disk1DS,disk2DS,disk3DS,disk4DS,disk5DS,disk6DS,disk7DS);
var disk = new Array();
var diskUnitNumbers = new Array();
for (var i in devices) {
if (devices[i] instanceof VcVirtualDisk) {
if (devices[i].deviceInfo!=null){
var unitNumber= devices[i].unitNumber;
var dl = new VcVirtualMachineRelocateSpecDiskLocator();
dl.diskId = devices[i].key;
if (dsArray[unitNumber] != null){
dl.datastore = dsArray[unitNumber].reference;
}else{
dl.datastore = targetDatastore.reference;
}
disk.push(dl);
}
}
}
The usual disclaimers apply: Use at your own risk!! No guarantee of support. Use on test VM to be sure it works as desired. Modify as needed to fit your own use-case.
UPDATE: I've just added "Relocate vm disks" workflow as an attachment here. This workflow ONLY moves disks to different datastores, not potentially the whole VM like the first one does... this allows the workflow to move disks even if the VM is powered on ... at least in my test is was successful