Automation

 View Only
  • 1.  Going crazy with Move-VM

    Posted Oct 26, 2017 07:41 PM

    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.



  • 2.  RE: Going crazy with Move-VM

    Posted Oct 27, 2017 03:27 AM

    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



  • 3.  RE: Going crazy with Move-VM

    Posted Oct 27, 2017 02:55 PM

    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. 



  • 4.  RE: Going crazy with Move-VM

    Posted Oct 27, 2017 04:08 PM

    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. 



  • 5.  RE: Going crazy with Move-VM

    Posted Oct 27, 2017 06:52 PM

    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.



  • 6.  RE: Going crazy with Move-VM

    Posted Oct 31, 2017 01:18 PM

    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. 



  • 7.  RE: Going crazy with Move-VM

    Posted Oct 31, 2017 01:47 PM

    Another thing to check, are there any folders on Datastore2 with the name of the VMs you are moving?