# 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)
}
}