Move-SCVirtualMachine

Moves a virtual machine stored in the VMM library or deployed on a host to a new location on a host.  

Description

The Move-SCVirtualMachine cmdlet moves a virtual machine stored in the System Center Virtual Machine Manager (VMM) library or deployed on a host to a new location on a host.

NOTE: To move a virtual machine from a host and store it in the library, you must use the Save-SCVirtualMachine cmdlet.

VMM includes storage migration features that let you move one or more virtual hard disks of a running virtual machine to a new location. You can use the Move-SCVirtualMachine cmdlet with the Move-SCVirtualHardDisk cmdlet to move Windows-based virtual hard disk (.vhd)  files and VMware-based virtual hard disk (.vmdk) files to a location on a different host. If the virtual machine is deployed on a host running Windows Server 2008 R2, or greater, the virtual machine experiences minimal service interruption. If the virtual machine is deployed on a VMware ESX host, VMM uses VMware VMotion so that no service interruption occurs. You can also use the Move-SCVirtualHardDisk cmdlet to move  a .vhd file or a .vmdk file from one location to another on the same host. 

VMM can use any of the following transfer methods (listed in the order in which VMM tries to use them):

- Hyper-V LIVE MIGRATION – If a virtual machine is running and is 
  deployed on a Hyper-V host that is a node of a Windows Server 2008 
  R2, or greater, host cluster, by default, VMM will use Hyper-V live 
  migration to move the virtual machine to another node in the cluster 
  without any disruption of service. For example, moving a running 
  virtual machine will not disconnect it from the network. Therefore, 
  the move is not perceived by users. You do not need to specify a path 
  for this type of move. You can start live migration of multiple virtual
  machines at the same time.

  For more information about Hyper-V live migration, see 
  http://go.microsoft.com/fwlink/?LinkId=147115.

- WINDOWS SERVER 2008 CLUSTER MIGRATION – VMM for 
  System Center 2012 continues to support Windows 2008 Cluster 
  Migration (sometimes called Quick Migration). Cluster Migration 
  lets you move a running virtual machine on a Hyper-V node of a 
  host cluster. It also lets you move a virtual machine that is in a 
  stopped or saved state and that is deployed  to another node 
  in the cluster. You can use Cluster Migration to move a virtual 
  machine in a stopped or saved state if the virtual machine is 
  deployed on either of the following nodes:

	* A node in a Windows Server 2008 cluster
	* A node in a Windows Server 2008 R2 cluster

  You do not need to specify a path for this type of move. Windows 
  Server 2008 Cluster Migration places the virtual machine in a 
  saved state during migration, which causes a temporary loss of 
  service to any users of that virtual machine.

- VMWARE LIVE MIGRATION – If a virtual machine deployed on a VMware 
  ESX host uses shared storage, VMM can use the VMware live 
  migration feature (VMware VMotion) to move the virtual 
  machine to a new host.  

  You do not need to specify a path for this type of move. The 
  Move-SCVirtualMachine cmdlet can use VMware VMotion to move a 
  virtual machine from one ESX host to another only if both ESX 
  hosts are in the same Datacenter container on the vCenter Server.

- CITRIX XENSERVER XENMOTION – If a virtual machine deployed on a 
  Citrix XenServer host uses shared storage and is part of the same 
  Resource Pool, VMM can use the XenServer live migration feature 
  (Citrix XenMotion) to move the virtual machine to a new host.  

  You do not need to specify a path for this type of move. The 
  Move-SCVirtualMachine cmdlet can use Citrix XenMotion to move a 
  virtual machine from one XenServer host to another only if both 
  XenServer hosts are in the same Resource Pool.

  This is the only supported method for moving a virtual machine 
  directly between XenServer hosts in VMM.

- SAN MIGRATION (Fibre Channel, iSCSI, or NPIV) – If the virtual 
  machine is on a host that is connected to a SAN and the virtual 
  machine is on a SAN LUN, VMM can move that virtual machine to 
  another host if that host has access to the same SAN. In a SAN 
  transfer, the target LUNs are redirected from the source host 
  to the destination host (no files are moved), which is why a 
  SAN transfer is much faster than moving virtual machine files 
  from one host to another over a local area network (LAN).

  VMM 2008 R2 supports SAN migration of virtual machines into 
  and out of a cluster.

  You must specify a path for this type of move. VMM can use an 
  NPIV SAN transfer if a host bus adapter (HBA) with NPIV support 
  is available. 

- NETWORK MIGRATION – If no faster method is available, VMM uses 
  a network transfer to move the virtual machine files from one 
  host to another over the LAN that connects the two hosts. You 
  can choose to use this transfer type even if the SAN transfer 
  type is available. You must specify a path for this type of move.

When more than one transfer type is available, the Move-SCVirtualMachine cmdlet automatically uses the fastest available transfer type to move a virtual machine. If the first method is not appropriate or available for the virtual machine you want to move, VMM tries to use the next method, and so on. If you want to force the use of a network transfer, specify the UseLAN parameter.

For more information about Move-SCVirtualMachine, type: "Get-Help Move-SCVirtualMachine -online".

Parameters

VM

Required? true
Accept Pipeline Input? true (ByValue)
Position? 0
Specifies a virtual machine object.

BlockLiveMigrationIfHostBusy

Required? false
Accept Pipeline Input? false
Position? named
Blocks retrying a Hyper-V live migration if the migration failed because the source host or the destination host is already participating in another live migration.

HighlyAvailable

Required? false
Accept Pipeline Input? false
Position? named
Specifies that a virtual machine will be placed on a Hyper-V host that is part of a host cluster. Configure this setting on a virtual machine, or on a template or hardware profile that will be used to create virtual machines.

JobGroup

Required? false
Accept Pipeline Input? false
Position? named
Specifies an identifier for a series of commands that will run as a set just before the final command that includes the same job group identifier runs. 

JobVariable

Required? false
Accept Pipeline Input? false
Position? named
Specifies that job progress is tracked and stored in the variable named by this parameter. 

Path

Required? false
Accept Pipeline Input? false
Position? named
Specifies the destination path for the operation.

Example formats:
 Local path	 -Path "F:\"
 UNC path		 -Path "\\Library\Templates"
 Volume GUID path -Path "\\?\Volume{4703c1ea-8ae7-11db-b473-00123f7603e3}\"
 VMware ESX path  –Path "[storage1]\MyVMwareFolderForVMs\MyVM.vmx"
 Citrix XenServer path - Path “Local storage[99b6212f-b63d-c676-25f9-d6c460992de7]”

Wildcards are supported for "Get" cmdlets and when you specify the UNC path:

Example format:
 UNC path		 -Path "\\VMHostServer\MyVMs\*VM*"

PROTipID

Required? false
Accept Pipeline Input? false
Position? named
Specifies the ID of the PRO tip that triggered this action. This allows for auditing of PRO tips.

RunAsynchronously

Required? false
Accept Pipeline Input? false
Position? named
Indicates that the job runs asynchronously so that control returns to the command shell immediately. 

StartVMOnTarget

Required? false
Accept Pipeline Input? false
Position? named
Specifies that a virtual machine starts as soon as it reaches its destination host.

UseCluster

Required? false
Accept Pipeline Input? false
Position? named
Forces the use of Cluster Migration for the transfer of a virtual machine that is in a saved state to a host, even if the cluster supports Hyper-V live migration.

UseLAN

Required? false
Accept Pipeline Input? false
Position? named
Forces a transfer over the local area network (LAN) even if a faster transfer mechanism, such as a storage area network (SAN) transfer, is available.

VMHost

Required? false
Accept Pipeline Input? true (ByValue)
Position? named
Specifies a virtual machine host object. VMM supports Hyper-V hosts, VMware ESX hosts, and Citrix XenServer hosts. 

For more information about each type of host, type: "Get-Help Add-SCVMHost -detailed". See the examples for a specific cmdlet to determine how that cmdlet uses this parameter.

Examples

1: Move a virtual machine from the library to a host.
PS C:\> $VM = Get-SCVirtualMachine | where { $_.Name -eq "VM01" -and $_.LibraryServer -eq "LibServer01.Contoso.com" }
PS C:\> $VMHost = Get-SCVMHost -ComputerName "VMHost01.Contoso.com"
PS C:\> Move-SCVirtualMachine -VMHost $VMHost -VM $VM -Path "D:\VirtualMachinePath"
The first command command gets the virtual machine object named VM01, which is currently stored in the VMM library on the library server named LibServer01, and stores the object in the $VM variable. This example assumes that only one virtual machine named VM01 is currently stored on LibServer01, and that, therefore, Get-SCVirtualMachine retrieves only one object.

The second command gets the host object named VMHost01 and stores the object in the $VMHost variable.

The last command moves the virtual machine from its current location in the library to the location D:\VirtualMachinePath on the host stored in $VMHost. The command automatically uses the fastest available transfer type. When the command completes, it returns information about the moved virtual machine.
2: Move a virtual machine from the library to a host asynchronously.
PS C:\> $VM = Get-SCVirtualMachine | where { $_.Name -eq "VM01" -and $_.LibraryServer -eq "LibServer01.Contoso.com" }
PS C:\> $VMHost = Get-SCVMHost -ComputerName "VMHost02.Contoso.com"
PS C:\> Move-SCVirtualMachine -VMHost $VMHost -VM $VM -Path "D:\VirtualMachinePath" -RunAsynchronously -JobVariable "MoveVMJob"
PS C:\> $MoveVMJob
The first two commands in this example are identical to the commands in example 1, except for the name of the VM host.

When the third command moves the virtual machine from its current location to D:\VirtualMachinePath on VMHost02, it uses the RunAsynchronously parameter to return control to the command shell immediately, and the JobVariable parameter to track the progress of the job. JobVariable stores a record of the job progress in the MoveVMJob variable. For the JobVariable parameter, you do not use the dollar sign ($) when the variable is created. 

The last command displays the contents of $MoveVMJob, which includes a description of the move job, its status, its progress, and other information.
3: Move a virtual machine from the library to a host by forcing a LAN transfer.
PS C:\> $VM = Get-SCVirtualMachine | where { $_.Name -eq "VM03" -and $_.LibraryServer -eq "LibServer01.Contoso.com" }
PS C:\> $VMHost = Get-SCVMHost -ComputerName "VMHost03.Contoso.com"
PS C:\> Move-SCVirtualMachine -VMHost $VMHost -VM $VM -Path "D:\VirtualMachinePath" -UseLAN
The first command gets the virtual machine object named VM03 on library server LibServer01 and stores the object in the $VM variable.

The second command gets the host object named VMHost03 and stores the object in the $VMHost variable.

The last command moves the virtual machine VM03 from its current location in the library to D:\VirtualMachinePath on VMHost03 using the UseLAN parameter to specify that the transfer use a network transfer even if faster transfer mechanisms are available.
4: Move a virtual machine between hosts by using VMware VMotion.
PS C:\> $VM = Get-SCVirtualMachine -Name "VM04" | where {$_.VMHost.Name -eq "ESXHost01"}
PS C:\> $VMHost = Get-SCVMHost | where {$_.Name -eq "ESXHost02"}
PS C:\> Move-SCVirtualMachine -VM $VM -VMHost $VMHost -Path "[Storage2]"
The first gets the virtual machine object named VM04 on ESXHost01 and stores the object in the $VM variable.

The second command gets the ESX host object named ESXHost02 and stores the object in the $VMHost variable.

In the last command, the Move-SCVirtualMachine cmdlet uses VMware VMotion to move the virtual machine from its current ESX host to the other ESX host. 

NOTE: The Move-SCVirtualMachine cmdlet can use the VMware VMotion feature to move a virtual machine from one ESX host to another only if both ESX servers are in the same Datacenter container on the vCenter Server.
5: Move a highly available virtual machine between nodes in a host cluster by using Hyper-V live migration.
PS C:\> $VM = Get-SCVirtualMachine -Name "HAVM05" | where {$_.VMHost.Name -eq "VMHVHostNode05A.Contoso.com"}
PS C:\> $VMHost = Get-SCVMHost | where {$_.Name -eq "VMHVHostNode05B.Contoso.com"}
PS C:\> Move-SCVirtualMachine -VM $VM -VMHost $VMHost -Path "D:\VMs\"
The first command gets the virtual machine object named HAVM05 on VMHVHostNode05A and stores the in the $VM variable. This example assumes that HAVM05 is a highly available virtual machine and that VMHVHostNode05A and VMHVHostNode05B are nodes in a Hyper-V host cluster.

The second command gets the host object named VMHVHostNode05B and stores the object in the $VMHost variable.

In the last command, the Move-SCVirtualMachine cmdlet uses live migration to move the virtual machine from VMHVHostNode05A to VMHVHostNode05B. 
6: Move a running virtual machine on a Hyper-V host to a new location on the same host.
PS C:\> $MoveVhdPath = "E:\VHDs” 
PS C:\> $VM = Get-SCVirtualMachine “VM06” 
PS C:\> $VMHost = Get-SCVMHost “VMHost06”
PS C:\> $HostPath = "E:\VirtualMachinePath" 
PS C:\> $JobGroupID = [System.Guid]::NewGuid().ToString()
PS C:\> Move-SCVirtualHardDisk -IDE -Bus 1 -Lun 1 -Path $MoveVhdPath -JobGroup $JobGroupID
PS C:\> Move-SCVirtualMachine -VM $VM -VMHost $VMHost -Path $HostPath -JobGroup $JobGroupID
The first command stores the string "E:\VHDs" in $MoveVhdPath. This is the path to which you want to move the virtual hard disk of the virtual machine.

The second command gets the virtual machine object named VM06 and stores the object the $VM variable.

The third command gets the host object named VMHost06 and stores the object in the $VMHost variable. This example assumes that VMHost06 is a Hyper-V host.

The fourth command stores the string "E:\VirtualMachinePath" in the $HostPath variable. This is the path to which you want to move VM06.

The fifth command creates a new GUID string and stores it in the $JobGroupID variable. This GUID is a job group ID that functions as an identifier that groups subsequent commands that include this identifier into a single job group.

The sixth command sets the virtual hard disk path to the value stored in $MoveVhdPath and it connects the virtual hard disk to Bus 1 and LUN 1 on the virtual IDE controller on the virtual machine. This command uses the JobGroup parameter to specify that it does not actually run until the Move-SCVirtualMachine cmdlet triggers the running of any commands in the JobGroup list.

The last command runs any commands that contain $JobGroupID (in this case, Move-SCVirtualHardDisk), and it runs Move-SCVirtualMachine. As a result, VM06 (a running virtual machine) is moved from its current location to E:\VirtualMachinePath on the same host. The virtual machine’s virtual hard disk is moved to E:\VHDs.

NOTE: You can also move a running virtual machine from one Hyper-V host to another Hyper-V host.

See Also