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
- 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. **
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)
- }
- }
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.
PowerShell Code Repository