10 Replies Latest reply on May 12, 2010 1:34 PM by LucD

    Move-VM between datastores

    jsintz Hot Shot

      I am attempting to move a VM to a new host, but when I exectue the following command I get an error stating the the destination container must be in the same datacenter.

       

      move-vm -VM mytestvm -Destination (get-vmhost vhost2.mydomain.com) -Datastore my_newdatastore

       

      Structure

       

      vDataCenter_1

      vCluster_1

         vHost_1

           mytestvm

       

      vDataCenter_2

      vCluster_2

         vHost2

           

          

       

      The VM is powered off and I am able to move the VM via virtualCenter without any errors or issues. Why can't I do the same via the "move-vm" powercli cmdlet?

        • 1. Re: Move-VM between datastores
          LucD Guru
          Community WarriorsUser ModeratorsvExpert

          Afaik sVmotion only works between shared storage.

          That's why the cmdlet tells you the destination has to be in the same datacenter.

           

          If the guest is powered off you try the Copy-DatastoreItem to move the guest's folder from one datastore to the other datastore.

          You have to unregister and register the guest before doing that.

           

           

           

           

          ____________

          Blog: LucD notes

          Twitter: lucd22

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Move-VM between datastores
            jsintz Hot Shot

            Why does the cold migration work from within virtual center? I am able to migrate this vm back and forth between these two datacenters with and without changing the datastore via virtualcenter. I don't have to unregister/register or move folders, just power off the vm, click migrate, and off it goes.

            • 3. Re: Move-VM between datastores
              LucD Guru
              Community WarriorsvExpertUser Moderators

              Are you sure you're not using Andrew Kutz's SVmotion plugin ?

              Just tried it again in my vCenter (build 208111) and I can only see datastores that are in the same datacenter.

               

               

               

               

              ____________

              Blog: LucD notes

              Twitter: lucd22

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Move-VM between datastores
                jsintz Hot Shot

                Absolutly 100% sure I am not using Mr. Kutz's SVmotion plugin (not installed). Also, I am not doing a storage vmotion (specifically). I am doing a cold migration between two differnet hosts in two different datacenters with two diffent storage pools using virtualcenter (build 208111) and it works as long as the VM is powered off. The same, powered off, VM will NOT move when I use the Move-VM cmdlet.

                • 5. Re: Move-VM between datastores
                  LucD Guru
                  Community WarriorsvExpertUser Moderators

                  Ok, I think I see what you are doing.

                  You select Migrate and then the Host and Datastore option.

                   

                  That won't work with Move-VM in the current build.

                  But you can use the RelocateVM method.

                  $vmName = <vmname>
                  $tgtDS = <target-datastorename>
                  $tgtHost = <target-esxname>
                  
                  $vm = Get-VM $vmName | Get-View
                  $esx = Get-VMHost $tgtHost | Get-View
                  $parent = $esx.Parent
                  while($parent.Type -ne "Datacenter"){
                       $parent = (Get-View $parent).Parent
                  }
                  $dc = Get-View $parent
                  $spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
                  $spec.datastore = (Get-Datastore $tgtDS | Get-View).MoRef
                  $spec.host = $esx.MoRef
                  $spec.Pool = (Get-Datacenter $dc.Name | Get-ResourcePool -Name "Resources" | Get-View).MoRef
                  $vm.RelocateVM($spec,"defaultPriority")
                  

                  Sorry about the confusion.

                   

                   

                  ____________

                  Blog: LucD notes

                  Twitter: lucd22

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: Move-VM between datastores
                    jsintz Hot Shot

                    Awesome. Thank you!

                     

                    Let me give it a try.

                    • 7. Re: Move-VM between datastores
                      jsintz Hot Shot

                      Still having a problem with different datacenters. I get the following error now.

                       

                      "The input arguments had entities that did not belong to the same datacenter."

                      • 8. Re: Move-VM between datastores
                        LucD Guru
                        Community WarriorsvExpertUser Moderators

                        Just to make sure, you did specify a host from the target datacenter ?

                        Tested it again and for me it works.

                         

                         

                         

                         

                        ____________

                        Blog: LucD notes

                        Twitter: lucd22

                        Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                        • 9. Re: Move-VM between datastores
                          jsintz Hot Shot

                          When I run script as-is I get the following error

                           

                          Exception calling "RelocateVM" with "2" argument(s): "The input arguments had entities that did not belong to the same datacenter."

                          At C:\Scripts\vps\vmRelocate_test.ps1:27 char:15

                          + $vm.RelocateVM <<<< ($spec,"defaultPriority")

                              + CategoryInfo          : NotSpecified: ( [], MethodInvocationException

                              + FullyQualifiedErrorId : DotNetMethodException

                           

                          I included a "write-host" statement after each variable so I could see what it was doing and this is the output

                           

                          $vm = VMware.Vim.VirtualMachine

                          $esx = VMware.Vim.HostSystem

                          $parent = ClusterComputeResource-domain-c103295

                          while $parent = Folder-group-h80618

                          $dc = Datacenter-datacenter-80616

                          $spec = VMware.Vim.Datacenter

                          $spec.datastore = VMware.Vim.VirtualMachineRelocateSpec

                          $spec.host = Datastore-datastore-113654

                          $spec.Pool = HostSystem-host-104044

                           

                          Exception calling "RelocateVM" with "2" argument(s): "The input arguments had entities that did not belong to the same datacenter."

                          At C:\Scripts\vps\vmRelocate_test.ps1:27 char:15

                          + $vm.RelocateVM <<<< ($spec,"defaultPriority")

                              + CategoryInfo          : NotSpecified: ( [], MethodInvocationException

                              + FullyQualifiedErrorId : DotNetMethodException

                          • 10. Re: Move-VM between datastores
                            LucD Guru
                            User ModeratorsCommunity WarriorsvExpert

                            Could you insert before the last line ($vm.RelocateVM...) a new line with $spec in it ?

                            ...
                            $spec                 # Add this line
                            $vm.RelocateVM...
                            

                            This should dump the contents of the VirtualMachineRelocateSpec object.

                            From the output in your previous reply I have the impression something went wrong there.

                             

                             

                             

                             

                            ____________

                            Blog: LucD notes

                            Twitter: lucd22

                            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz