Automation

 View Only
Expand all | Collapse all

cmdlet move-vm to migrate to another dc and folder vm

  • 1.  cmdlet move-vm to migrate to another dc and folder vm

    Posted Jul 24, 2020 12:45 PM

    Hello,

    We are in the process to migrate all our VMs to a new datacenter (on vcsa 6.7)

    We are facing two problems. One is that using move-vm we have to assign the new cluster and the new vsan datastore. It seem not possible to use move-vm in two step, one to change cluster and the other step to do a svmotion in the new datastore. It seems that using this two step method is a better way because in that case svmotion using VAAI. am i right?

    The other issue is that using some script found on the web we have created a csv file with the name and the blue folder path, but it seems not possible to import this file so move-vm can use it to import vm to his location.



  • 2.  RE: cmdlet move-vm to migrate to another dc and folder vm

    Posted Jul 24, 2020 12:51 PM

    Your first issue seems to be a matter of where the storage is visible (connected).
    Can you mount it in the 2nd vCenter?

    What exactly do you mean by "not possible to import"?



  • 3.  RE: cmdlet move-vm to migrate to another dc and folder vm

    Posted Jul 24, 2020 01:19 PM

    Hello, thanks for your quick answer.

    We are on the same vcenter, the old datacenter is using SAN FC to store VM and the new datacenter is using vSAN. We have presented storage SAN on the new datacenter (just for the migration)  and this create alert that storage are presented on both datacenter, but this is not an issue. Just is it possible to split task move-vm in two, one to move using vmotion and the next one to svmotion (and the last one should be to move vm to the final folder destination)

    For the blue folder the csv file look like this :

    Name‚"BlueFolderPath"

    vm1‚"/folder1/subfolder1"

    i can't use value "/folder1/subfolder1" with -inventorylocation

    i try with "NEWDC/folder1/subfolder1" and "NEWDC/vm/folder1/subfolder1" but same result : "Could find foldercontainer with name"



  • 4.  RE: cmdlet move-vm to migrate to another dc and folder vm

    Posted Jul 24, 2020 01:44 PM

    Yes, you should be able to do the move in those steps, provided the storage is accessible to the ESXi nodes in that new datacenter.

    The InventoryLocation parameter expects a folder object.

    You would first need to get the folder object itself from that path.

    You could use the logic I used in Re: Export/Import Folder Structure



  • 5.  RE: cmdlet move-vm to migrate to another dc and folder vm

    Posted Jul 24, 2020 02:20 PM

    If i use move-vm without specifying datastore (because on the first step the vm won't change of datastore) i've got this error :

    PS C:\> move-vm -vm vm1 -Destination (get-cluster -Name NEWCLUS) -portgroup (get-vdswitch NEW-DVS | get-vdportgroup -name namevlan)

    WARNING: PowerCLI scripts should not use the 'VirtualSwitch' property of VmwareVDPortgroup type. The property will be removed in a future release.

    move-vm : 24/07/2020 16:04:53   Move-VM         A specified parameter was not correct: RelocateSpec

    At line:1 char:1

    + move-vm -vm vm1 -Destination (get-cluster -Name NEWCLUS ...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [Move-VM], VimException

        + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

    move-vm working fine by adding -datastore (get-datastore -name vSAN) -storagePolicy $policy -diskstorageformat thin to the previous command.

    For the move to the  folder vm i tried your script. So the export part give me a listing.

    But the import seems to only create the folder and not moving the vms? We already succeeded to recreate all folders, but not able to move  vm at their locations.

    By the way the version of powercli :

    7.0.0.15939650  VMware.Vim

    12.0.0.15939657 VMware.VimAutomation.Cis.Core

    12.0.0.15939652 VMware.VimAutomation.Common

    12.0.0.15939655 VMware.VimAutomation.Core

    12.0.0.15939651 VMware.VimAutomation.Sdk

    12.0.0.15940185 VMware.VimAutomation.Vds



  • 6.  RE: cmdlet move-vm to migrate to another dc and folder vm

    Posted Jul 24, 2020 02:30 PM

    When you use the Datastore parameter on the first Move-VM, pointing to the datastore where the VM currently sits, it should do a vMotion.

    If the folders are already there, you can use the logic from Re: Move VMs to Folders



  • 7.  RE: cmdlet move-vm to migrate to another dc and folder vm

    Posted Jul 24, 2020 02:49 PM

    Thanks for the information, i will come back to you next week.



  • 8.  RE: cmdlet move-vm to migrate to another dc and folder vm

    Posted Jul 27, 2020 08:37 AM

    The vmotion didn't work using the original datastore, indeed, cmdlet return this message :

    "The specified parameter 'Datastore' expects a single value, but your name criteria 'OLD Datatore' corresponds to multiple values."

    Which is indeed true as the datastore are presented to both old and new cluster.

    Using GUI to do a vmotion does not cause an issue but doing the same in powercli seems not possible :smileysad:

    So i think we will migrate using vmotion and svmotion at the same time and probably have a slowler migration.

    Many thanks for the get-folderbypath  i ran some test and it's working as expected. I just have to modify the csv file, because comma between the value was missing.



  • 9.  RE: cmdlet move-vm to migrate to another dc and folder vm

    Posted Jul 27, 2020 08:44 AM

    Did you use the Server parameter on the Get-Datastore cmdlet?

    That way you specify on which vCenter you want to retrieve the datastore.



  • 10.  RE: cmdlet move-vm to migrate to another dc and folder vm

    Posted Jul 27, 2020 09:16 AM

    No, as we are on the same vcenter, we are just migrating to a new datacenter with vSAN Enabled

    I modified script to this :

    >$vmlan = Get-VM -Name $vm | get-networkadapter

    >move-vm -VM (Get-VM -Name $vm) -Destination (get-cluster -name NEWCLUS) -datastore ( Get-VM -Name $vm | Get-Datastore ) -portgroup ( get-vdswitch NEWDVS | get-vdportgroup -name $vmlan.networkname )

    move-vm : 27/07/2020 11:10:57   Move-VM         A specified parameter was not correct: PlacementSpec.relocateSpec

    At line:1 char:1

    + move-vm -VM (Get-VM -Name $vm) -Destination (get-cluster -name NEWCLUS ...

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [Move-VM], VimException

        + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVM

    move-vm -VM (get-vm -name $vm) -destination (get

    So still an issue with relocateSpec when trying a single vmotion without svmotion.



  • 11.  RE: cmdlet move-vm to migrate to another dc and folder vm
    Best Answer

    Posted Jul 27, 2020 09:26 AM

    Then you can use the RelatedObject parameter.

    Get-Datastore -Name xyz -RelatedObject (Get-Cluster -Name newcluster)



  • 12.  RE: cmdlet move-vm to migrate to another dc and folder vm

    Posted Jul 27, 2020 10:02 AM

    That was that !  Thanks for the -relatedobject parameter   and for the move to folder script.

    Now we have to merge all of that and try with runasync to get some parallelization.

    We can close this thread.

    Many thanks again :smileyhappy: