Move-VM Command | Vmware PowerCLI Reference

Move-VM

This cmdlet moves a virtual machine to the location that is specified by the Destination or the Datastore parameters. The destination must be a folder, host, cluster, or a resource pool. You can move a virtual machine to a DRS cluster. Moving a virtual machine to the top level of a non-DRS cluster is only possible if the virtual machine is in a resource pool in that cluster. If the virtual machine is outside the non-DRS cluster, you need to specify a virtual machine host in that cluster as destination. When moving virtual machines that are powered on, vMotion is used. You can move storage and compute resources simultaneously. You can move virtual machines between vCenter Server systems of vSphere version 6.0 and later. To specify a server different from the default one, use the Server parameter. When you move a virtual machine from one vCenter Server system to another, only datastores are supported as storage destinations.

Syntax

Move-VM
[ [-Destination ] < VIContainer > ]
[-AdvancedOption < AdvancedOption[] > ]
[-Datastore < StorageResource > ]
[-DestinationSslThumbprint < String > ]
[-DiskStorageFormat < VirtualDiskStorageFormat > ]
[-InventoryLocation < FolderContainer > ]
[-NetworkAdapter < NetworkAdapter[] > ]
[-PortGroup < VirtualPortGroupBase[] > ]
[-ProgressAction < ActionPreference > ]
[-RunAsync ]
[-Server < VIServer[] > ]
[-StoragePolicy < StoragePolicy > ]
[-VMotionPriority < VMotionPriority > ]
[CommonParameters]

Parameters

Required Parameter Name Type Position Features Description
required
VM VirtualMachine[] named
  • pipeline
  • wildcards
Specifies the virtual machines you want to move to another location.
optional Destination VIContainer 1
  • pipeline
  • wildcards
Specifies a folder, host, cluster, or a resource pool where you want to move the virtual machines. If a data center is specified for the Destination parameter, you can move the virtual machines to the data center's "vmFolder" folder. The "vmFolder" is a system folder and is guaranteed to exist. Passing values to this parameter through a pipeline is deprecated and will be deactivated in a future release.
optional AdvancedOption AdvancedOption[] named
This parameter is only applicable when a DatastoreCluster object is passed to the Datastore parameter. Specifies one or more rules for the placement of the virtual machines that you want to relocate. To indicate that you want to store the virtual machines on different datastores, pass an SdrsVMAntiAffinityRule object to the parameter. You can set more than one Storage DRS (SDRS) virtual machine anti-affinity rules. To indicate that you want to store the virtual machine disks on different datastores, pass an SdrsVMDiskAntiAffinityRule object to the parameter. You can set only one SDRS virtual machine disk anti-affinity rule.
optional Datastore StorageResource named
  • wildcards
Specifies the datastore or datastore cluster where you want to move the virtual machines. When you pass a datastore cluster to the Datastore parameter, you can also set the AdvancedOption parameter.
optional DestinationSslThumbprint String named
Specifies the SSL thumbprint of the destination server when moving virtual machines between vCenter Server systems.
optional DiskStorageFormat VirtualDiskStorageFormat named
Specifies a new storage format for the hard disk of the virtual machine you want to move. This parameter is applicable only when moving a virtual machine to a different datastore, using the Datastore parameter. This parameter accepts Thin, Thick, and EagerZeroedThick values.
optional InventoryLocation FolderContainer named
Specifies a data center or a virtual machine folder where you want to move the virtual machine.
optional NetworkAdapter NetworkAdapter[] named
Specifies the virtual machine network adapters you want to migrate to a new port group.
optional PortGroup VirtualPortGroupBase[] named
  • wildcards
Specifies the destination port groups for the specified virtual machine network adapters. The number of the port groups should be one or equal to the number of the specified network adapters. If one port group and more than one network adapters are specified, you can migrate all network adapters to the specified port group. You cannot use this parameter with the Network parameter.
optional ProgressAction ActionPreference named
optional RunAsync SwitchParameter named
Indicates that the command returns immediately without waiting for the task to complete. In this mode, the output of the cmdlet is a Task object. For more information about the RunAsync parameter, run "help About_RunAsync" in the VMware PowerCLI console.
optional Server VIServer[] named
  • wildcards
Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of the Connect-VIServer cmdlet.
optional StoragePolicy StoragePolicy named
Specifies a new StoragePolicy for the virtual machine you want to move. The StoragePolicy is attached to VMHome and all hard disks.
optional VMotionPriority VMotionPriority named
Determines the priority that you should use for a vMotion operation.
Move-VM
[ [-Destination ] < VIContainer > ]
[-AdvancedOption < AdvancedOption[] > ]
[-Datastore < StorageResource > ]
[-DestinationSslThumbprint < String > ]
[-DiskStorageFormat < VirtualDiskStorageFormat > ]
[-InventoryLocation < FolderContainer > ]
[-Network < Network[] > ]
[-NetworkAdapter < NetworkAdapter[] > ]
[-ProgressAction < ActionPreference > ]
[-RunAsync ]
[-Server < VIServer[] > ]
[-StoragePolicy < StoragePolicy > ]
[-VMotionPriority < VMotionPriority > ]
[CommonParameters]

Parameters

Required Parameter Name Type Position Features Description
required
VM VirtualMachine[] named
  • pipeline
  • wildcards
Specifies the virtual machines you want to move to another location.
optional Destination VIContainer 1
  • pipeline
  • wildcards
Specifies a folder, host, cluster, or a resource pool where you want to move the virtual machines. If a data center is specified for the Destination parameter, you can move the virtual machines to the data center's "vmFolder" folder. The "vmFolder" is a system folder and is guaranteed to exist. Passing values to this parameter through a pipeline is deprecated and will be deactivated in a future release.
optional AdvancedOption AdvancedOption[] named
This parameter is only applicable when a DatastoreCluster object is passed to the Datastore parameter. Specifies one or more rules for the placement of the virtual machines that you want to relocate. To indicate that you want to store the virtual machines on different datastores, pass an SdrsVMAntiAffinityRule object to the parameter. You can set more than one Storage DRS (SDRS) virtual machine anti-affinity rules. To indicate that you want to store the virtual machine disks on different datastores, pass an SdrsVMDiskAntiAffinityRule object to the parameter. You can set only one SDRS virtual machine disk anti-affinity rule.
optional Datastore StorageResource named
  • wildcards
Specifies the datastore or datastore cluster where you want to move the virtual machines. When you pass a datastore cluster to the Datastore parameter, you can also set the AdvancedOption parameter.
optional DestinationSslThumbprint String named
Specifies the SSL thumbprint of the destination server when moving virtual machines between vCenter Server systems.
optional DiskStorageFormat VirtualDiskStorageFormat named
Specifies a new storage format for the hard disk of the virtual machine you want to move. This parameter is applicable only when moving a virtual machine to a different datastore, using the Datastore parameter. This parameter accepts Thin, Thick, and EagerZeroedThick values.
optional InventoryLocation FolderContainer named
Specifies a data center or a virtual machine folder where you want to move the virtual machine.
optional Network Network[] named
Specifies the destination networks for the specified virtual machine network adapters. The number of networks should be one or equal to the number of the specified network adapters. If one network and more than one network adapters are specified, you can migrate all network adapters to the specified network. You cannot use this parameter with the PortGroup parameter.
optional NetworkAdapter NetworkAdapter[] named
Specifies the virtual machine network adapters you want to migrate to a new port group.
optional ProgressAction ActionPreference named
optional RunAsync SwitchParameter named
Indicates that the command returns immediately without waiting for the task to complete. In this mode, the output of the cmdlet is a Task object. For more information about the RunAsync parameter, run "help About_RunAsync" in the VMware PowerCLI console.
optional Server VIServer[] named
  • wildcards
Specifies the vCenter Server systems on which you want to run the cmdlet. If no value is provided or $null value is passed to this parameter, the command runs on the default servers. For more information about default servers, see the description of the Connect-VIServer cmdlet.
optional StoragePolicy StoragePolicy named
Specifies a new StoragePolicy for the virtual machine you want to move. The StoragePolicy is attached to VMHome and all hard disks.
optional VMotionPriority VMotionPriority named
Determines the priority that you should use for a vMotion operation.

Output

VMware.VimAutomation.ViCore.Types.V1.Inventory.VirtualMachine

Examples

Example 1

Get-VM -Name VM | Move-VM -Destination 10.23.112.235

Moves the virtual machine named VM from its current location to the host on IP address 10.23.112.235.

Example 2

Move-VM -VM VM -Destination Folder

Moves the virtual machine to a folder called Folder. Note that you can move virtual machines only to folders containing virtual machines (the 'blue' folders in the vSphere Client).

Example 3

Move-VM -VM 'MyVM' -Destination 'MyDestination'

Moves a powered on virtual machine from one existing host to another by using vMotion, passing parameters by name.

Example 4

Move-VM -VM 'MyVM' -Datastore 'MyDatastore'

Moves a powered on virtual machine from one existing datastore to another by using storage vMotion, passing parameters by name.

Example 5

$myDatastoreCluster1 = Get-DatastoreCluster -Name 'MyDatastoreCluster1'
Move-VM -VM 'MyVM1' -Datastore $myDatastoreCluster1

Moves the MyVM1 virtual machine to any datastore in the specified datastore cluster.

Example 6

$myDatastoreCluster1 = Get-DatastoreCluster -Name 'MyDatastoreCluster1'
$myVm2 = Get-VM -Name 'MyVM2'
$vmAntiAffinityRule = New-Object -TypeName VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.SdrsVMAntiAffinityRule -ArgumentList $myVm2
Move-VM -VM 'MyVM1' -Datastore $myDatastoreCluster1 -AdvancedOption $vmAntiAffinityRule

Moves the MyVM1 virtual machine to the specified datastore cluster and sets a VM anti-affinity rule for the placement of the virtual machine. You can place the MyVM1 virtual machine on any datastore in the specified datastore cluster that does not contain the MyVM2 virtual machine.

Example 7

$myVm1 = Get-VM -Name 'MyVM1'
$vmdks = Get-Harddisk -VM $myVm1
$myDatastoreCluster1 = Get-DatastoreCluster -Name 'MyDatastoreCluster1'
$vmdkAntiAffinityRule = New-Object -TypeName VMware.VimAutomation.ViCore.Types.V1.DatastoreManagement.SdrsVMDiskAntiAffinityRule -ArgumentList $vmdks
Move-VM -VM '$myVm1' -Datastore $myDatastoreCluster1 -AdvancedOption $vmdkAntiAffinityRule

Moves the MyVM1 virtual machine to the specified datastore cluster and sets a VM disk anti-affinity rule for the placement of the virtual machine. You can store the disks of the MyVM1 virtual machine on different datastores in the specified datastore cluster.

Example 8

Get-VM -Name 'MyVM' -Server 'MyServer' | Move-VM -Destination 'NewHost' -Datastore 'DatastoreOnNewHost' -DiskStorageFormat 'Thin'

Moves a powered off virtual machine to another datastore on another host and changes its disk storage format to thin.

Example 9

Connect-VIServer 'myVC1' -Username <username> -Password <pass>
Connect-VIServer 'myVC2' -Username <username> -Password <pass>

$vm = Get-VM 'myVM' -Location 'myVMhostOnVC1'
$destination = Get-VMHost 'MyVMhostOnVc2'
$networkAdapter = Get-NetworkAdapter -VM $vm
$destinationPortGroup = Get-VDPortgroup -VDSwitch 'myVDSwitchOnVC2' -Name 'myPortGroup'
$destinationDatastore = Get-Datastore 'MyDatastoreOnVc2'

$vm | Move-VM -Destination $destination -NetworkAdapter $networkAdapter -PortGroup $destinationPortGroup -Datastore $destinationDatastore

Moves the MyVM virtual machine from one vCenter Server system to another. Specifies myPortGroup as the destination port group and MyDatastoreOnVc2 as the destination datastore.

Example 10

Move-VM -VM 'MyVM' -Datastore 'MyDatastore' -StoragePolicy $policy

Moves a powered on virtual machine from one existing datastore to another by using storage vMotion, and attaches the $policy storage policy to it.

Example 11

Connect-VIServer 'myVC1' -Username <username> -Password <pass>
Connect-VIServer 'myVC2' -Username <username> -Password <pass>

$vm = Get-VM 'myVM' -Location 'myVMhostOnVC1'
$destination = Get-VMHost 'MyVMhostOnVc2'
$networkAdapter = Get-NetworkAdapter -VM $vm
$destinationPortGroup = Get-VDPortgroup -VDSwitch 'myVDSwitchOnVC2' -Name 'myPortGroup'
$destinationDatastore = Get-Datastore 'MyDatastoreOnVc2'
$destinationStoragePolicy = Get-SpbmStoragePolicy 'MyStoragePolicyOnVc2'

$vm | Move-VM -Destination $destination -NetworkAdapter $networkAdapter -PortGroup $destinationPortGroup -Datastore $destinationDatastore -StoragePolicy $destinationStoragePolicy

Moves the MyVM virtual machine from one vCenter Server system to another. Specifies myPortGroup as the destination port group and MyDatastoreOnVc2 as the destination datastore. Attaches the MyStoragePolicyOnVc2 storage policy to VMHome and its hard disks.

Related Commands

VM

This cmdlet retrieves the virtual machines on a vCenter Server system.

This cmdlet moves virtual machines to another location.

This cmdlet creates a new virtual machine.

This cmdlet removes the specified virtual machines from the vCenter Server system.

This cmdlet restarts the specified virtual machines.

This cmdlet modifies the configuration of the virtual machine.

This cmdlet powers on virtual machines.

This cmdlet powers off virtual machines.

This cmdlet suspends virtual machines.

This cmdlet unlocks the specified virtual machine.

VMConsoleWindow

This cmdlet opens a window to the virtual machine's console.

VMGuest

This cmdlet retrieves the guest operating systems of the specified virtual machines.

This cmdlet restarts the virtual machine guest operating systems.

This cmdlet shuts down the specified virtual machine guest OS.

This cmdlet suspends the specified guest operating systems.

VMGuestDisk

This cmdlet retrieves storage volumes as seen by the virtual machines' guest operating systems.

VMGuestFile

This cmdlet copies files and folders from and to the guest OS of the specified virtual machines using VMware Tools.

VMQuestion

This cmdlet retrieves the pending questions for the specified virtual machines.

This cmdlet answers the specified virtual machine question.

VMResourceConfiguration

This cmdlet retrieves information about the resource allocation between the selected virtual machines.

This cmdlet configures resource allocation between the virtual machines.

VMScript

This cmdlet runs a script in the guest OS of each of the specified virtual machines.

VMStartPolicy

This cmdlet retrieves the start policy of the virtual machines on a vCenter Server system.

This cmdlet modifies the virtual machine start policy.