PoshCode Archive  Artifact Content

Artifact 4d69816c9afd057d73528e252ce1a0398ec07a83ea954ecce1f0c3f0b76d1b92:

  • File SVMotion-VM.ps1 — part of check-in [8c3ddd3736] at 2018-06-10 14:00:35 on branch trunk — Please note that the move-vm’s -datastore parameter ought to work but there seems to be a bug in it, hence the need for this script. ** (user: halr9000 size: 1304)

# encoding: ascii
# api: powershell
# title: SVMotion-VM
# description: Please note that the move-vm’s -datastore parameter ought to work but there seems to be a bug in it, hence the need for this script. **
# version: 0.1
# type: function
# author: halr9000
# license: CC0
# function: SVMotion-VM
# x-poshcode-id: 575
# x-derived-from-id: 584
# x-archived: 2008-09-15T21:30:05
#
# # Does “real” SVMotion of a VM. FWIW, Carter did it first here: http://communities.vmware.com/docs/DOC-6051, but it was made for PS V2 CTP2 which this function does not require. Plus, I like mine better.
#
# author: Hal Rottenberg
# Website/OpenID: http://halr9000.com
# purpose: does "real" SVMotion of a VM
# usage: get-vm | SVMotion-VM -destination (get-datastore foo)

function SVMotion-VM {
	param(
		[VMware.VimAutomation.Client20.DatastoreImpl]
		$destination
	)
	Begin {
		$datastoreView = get-view $destination
		$relocationSpec = new-object VMware.Vim.VirtualMachineRelocateSpec
		$relocationSpec.Datastore = $datastoreView.MoRef
	}
	Process {
		if ( $_ -isnot VMware.VimAutomation.Client20.VirtualMachineImpl ) {
			Write-Error "Expected VMware object on pipeline. skipping $_"
			continue
		}
		$vmView = Get-View $_
		$vmView.RelocateVM_Task($relocationSpec)
	}
}