vSphere PowerCLI Reference

Move-VM

Synopsis

Moves virtual machines to another location.

Syntax

Move-VM [-AdvancedOption <AdvancedOption[]>] [[-Destination] <VIContainer>] [-Datastore <StorageResource>] [-DiskStorageFormat <VirtualDiskStorageFormat>] [-RunAsync] [-VM] <VirtualMachine[]> [-Server <VIServer[]>] [-WhatIf] [-Confirm] [<CommonParameters>]

Related Commands

Online version
Get-VM
Remove-VM
New-VM
Set-VM
Start-VM
Stop-VM
Suspend-VM
Restart-VM

Detailed Description

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. Moving a virtual machine in a cluster is only possible if the virtual machine is in a resource pool in that cluster. If the virtual machine is outside the 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. To specify a server different from the default one, use the Server parameter.

Parameters

NameTypeDescriptionRequired?Pipeline InputDefault Value
VMVirtualMachine[]Specify the virtual machines you want to move to another location.truetrue (ByValue)
DestinationVIContainerSpecify a folder, host, cluster, or a resource pool where you want to move the virtual machines. If a datacenter is specified for the -Destination parameter, the virtual machines are moved to the datacenter'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 disabled in a future release.
falsetrue (ByValue)
AdvancedOptionAdvancedOption[]This parameter is only applicable when a DatastoreCluster object is passed to the Datastore parameter.
Specify one or more rules for the placement of the virtual machines that you want to relocate.

To indicate that VMs should be stored on different datastores, pass an SdrsVMAntiAffinityRule object to the parameter. You can set more than one Storage DRS (SDRS) VM anti-affinity rules.

To indicate that the VM disks should be stored on different datastores, pass an SdrsVMDiskAntiAffinityRule object to the parameter. You can set only one SDRS VM disk anti-affinity rule.
falsefalse
ConfirmSwitchParameterIf the value is $true, indicates that the cmdlet asks for confirmation before running. If the value is $false, the cmdlet runs without asking for user confirmation.falsefalse$true
DatastoreStorageResourceSpecify 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.falsefalse
DiskStorageFormatVirtualDiskStorageFormatSpecify 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.falsefalse
RunAsyncSwitchParameterIndicate 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 vSphere PowerCLI console.falsefalse
ServerVIServer[]Specify the vSphere servers on which you want to run the cmdlet. If no value is given to this parameter, the command runs on the default servers. For more information about default servers, see the description of Connect-VIServer.falsefalse
WhatIfSwitchParameterIndicate that the cmdlet is run only to display the changes that would be made and actually no objects are modified.falsefalse

Return Type

VirtualMachine

Notes

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 are able to move virtual machines only to folders containing virtual machines (the 'blue' folders in the vSphere Client).

-------------- Example 3 --------------

Move-VM -VM VM -Destination ResourcePool

Moves the virtual machine to the ResourcePool resourcepool. The ESX host does not change.

-------------- Example 4 --------------

$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 5 --------------

$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. The MyVM1 virtual machine will be placed on any datastore in the specified datastore cluster that does not contain the MyVM2 virtual machine.

-------------- Example 6 --------------

$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. The disks of the MyVM1 virtual machine will be stored on different datastores in the specified datastore cluster.


Copyright © 1998 - 2012 VMware, Inc. All rights reserved.