Are performing other actions on the VM between the moment you Get the VM and do the move?
Perhaps share your code, so we can try to recreate the issue you are seeing
Thanks, I want to try a few things out first. I will post the code if I don't make any progress, I'm sure that it's some small thing I'm doing wrong.
Ok, I tried something very simple.
get-datastore 'datastore1' | get-vm | select -First 2 | move-vm -Datastore (get-datastore 'datastore2')
When I do that I get "Move-VM Operation is not valid due to the current state of the object.", and the VMs proceed to migrate to the new datastore.
Windows 10 64-bit
VMware PowerCLI 6.5.1 build 5377412
VMware Cis Core PowerCLI Component 6.5 build 6870462
VMware VimAutomation Core PowerCLI Component 6.5 build 6234650
Odd, I thought I upgraded to the latest version of PowerCLI, but I'll try again, and hope that it fixes the issue. The VMs move just fine, but the error still occurs.
These datastores are both visible to the ESXi nodes where these VMs are running?
The later PowerCLI releases (6.5.2 and 6.5.3) did not upgrade all modules.
Look at the version of all modules, or check VMware.PowerCLI.
The datastores are visible to every ESXi host in that datacenter, and I'm explicitly getting the datastore by typing
Get-Datacenter "DC" | Get-Datastore "Name".
The weird thing is that everything moves just fine, but it still produces errors. I plan on posting the script, but of course, work is interfering with my plans, and I want to make sure that I'm not overlooking some small detail.
Another thing to check, are there any folders on Datastore2 with the name of the VMs you are moving?