I'm writing a script to move some VMs off of one datastore. Essentially, I'm collecting some VMs names, filtering them for the ones I want to move, I'm grabbing the first 2 VMs, and saying Move-VM -datastore $theDatastore.
I keep getting this error "Move-VM Operation is not valid due to the current state of the object.", but the VMs move. For the most part, the script seems to be working, but I can't figure out why I'm getting this error. I'm still trying a few things, but I was curious if anyone has ran into this issue. When I do perform the Move-VM command, there are two VMs that are in a variable, but if I try Get-VM $VariableName, the VMs come up correctly.
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.
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.