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.
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
I'm running:
Windows 10 64-bit
PowerCLI Version
----------------
VMware PowerCLI 6.5.1 build 5377412
---------------
Component Versions
---------------
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.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference