PoshCode Logo PowerShell Code Repository

SVMotion-VM by halr9000 3 years ago (modification of post by halr9000 view diff)
View followups from halr9000 | diff | embed code: <script type="text/javascript" src="http://PoshCode.org/embed/575"></script>download | new post


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.

  1. # author: Hal Rottenberg
  2. # Website/OpenID: http://halr9000.com
  3. # purpose: does "real" SVMotion of a VM
  4. # usage: get-vm | SVMotion-VM -destination (get-datastore foo)
  5.  
  6. function SVMotion-VM {
  7.         param(
  8.                 [VMware.VimAutomation.Client20.DatastoreImpl]
  9.                 $destination
  10.         )
  11.         Begin {
  12.                 $datastoreView = get-view $destination
  13.                 $relocationSpec = new-object VMware.Vim.VirtualMachineRelocateSpec
  14.                 $relocationSpec.Datastore = $datastoreView.MoRef
  15.         }
  16.         Process {
  17.                 if ( $_ -isnot VMware.VimAutomation.Client20.VirtualMachineImpl ) {
  18.                         Write-Error "Expected VMware object on pipeline. skipping $_"
  19.                         continue
  20.                 }
  21.                 $vmView = Get-View $_
  22.                 $vmView.RelocateVM_Task($relocationSpec)
  23.         }
  24. }

Submit a correction or amendment below (
click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:


Remember me