How do I svMotion a single disk in PowerCLI 5.5?
Trying Set-HardDisk
gives the following warning:
WARNING: Parameter 'Datastore' is obsolete. 'Datastore' parameter is obsolete. To move hard disk to another datastore and change it's storage format, use 'Move-HardDisk' cmdlet instead.
Set-HardDisk
fails anyway with a message that the disk is locked (hence I guess you can't use it for an online migration).
Move-HardDisk
only seems to be able to move disks in offline mode too (cold migration), however I'd like to perform a Storage vMotion.
Move-VM
can only move all disks of a VM, which is not what I want. (Too many and too big disks on a VM, will never fit on one destination LUN)
In essence, I'd like to script what you can do with the "advanced" dialog for migrating disks in vCenter Server. But how?
Not sure which vSphere and PowerCLI version you are running, but I checked again (vSphere 6.5 and PowerCLI 6.5R1), and the following works for me (with the VM powered on).
Get-HardDisk -VM MyVM -Name 'Hard Disk 1' | Move-HardDisk -Datastore MyDS
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Afaik, you will have to use the RelocateVM method.
In there you can specify per harddisk where you to move it.
See for example Migration to a New SAN with HardDisk to separate LUNs
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Oh man :smileygrin: That's really sick.
So you have to create these RelocateSpec and RelocateSpecDiskLocator objects etc. and then use some part of the API instead of having a high-level function for this task, wow.
As far as I understand it, internally to ESXi an svMotion actually is a vMotion, which is why you have to set a destination for all disks, even though you want to move only one of them, again wow.
Well, this also explains why the event log of vCenter Server shows both vMotion and svMotion as "Migrating from a to b" with no info about the datastore being changed for any specific disk (it only shows the destination disk in case you chose to migrate the VMX I guess).
Not sure which vSphere and PowerCLI version you are running, but I checked again (vSphere 6.5 and PowerCLI 6.5R1), and the following works for me (with the VM powered on).
Get-HardDisk -VM MyVM -Name 'Hard Disk 1' | Move-HardDisk -Datastore MyDS
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hey Luc,
Just wanted to thank you and the original poster for this thread.. I have a task to migrate some servers from one SAN to a new one and 2 of the VMs have 27 VMDKs which reside on over 10 datastores. I was going to migrate them by hand using the wizard, but when I saw this thread I realized I could script it AND could run it with the -runasync switch and do them all at once with the VM powered off.
Thanks!
Yeah ok, the point is you have to go through "Get-VM" first...
You can't simply "Move-HardDisk" like this:
$hdsrc = Get-HardDisk -Datastore $srcds
foreach ($hd in $hdsrc) {
Move-HardDisk $hd -Datastore $dstds
...
Because then it will tell you that the disk is locked.
Just wondering when the VM powered off requirement was lifted.
In vSphere 6.x and with PowerCLI 6.5R1 this seems to work with a powered on VM as well.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Since I'm using 5.5 and "Get-HardDisk... | Move-HardDisk ..." works alright, I'm not sure what requirement you mean.
Didn't you say that the VM needed to be powered off for Move-Harddisk to work?
In vSphere 6.* the VM can stay powered on.
I was wondering if that VM powered off requirement was lifted in 6.0.
I don't have a 5.5 to test anymore :smileygrin:
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I said you have to use Move-Harddisk in combination with Get-VM (like you showed).
Simply using "Move-HardDisk" like this is not working:
$hdsrc = Get-HardDisk -Datastore $srcds
foreach ($hd in $hdsrc) {
Move-HardDisk $hd -Datastore $dstds
...
I'm not an expert, so LucD can correct me, but something like this may work...
foreach ($vm in (Get-VM)) (
$hdsrc = Get-HardDisk -VM $vm -Datastore $srcds
foreach ($hd in $hdsrc) {
Move-HardDisk $hd -Datastore $dstds }
}
I guess it would, the point being: You have to get the $hd object from "Get-HardDisk -VM $vm -Datastore $srcds"
Just getting it from "Get-HardDisk -Datastore $srcds" and iterating over that, does not seem to be enough.
Note: it seems you are not able to move specifically the VM config (vmx + swap + snapshots) this way or with Move-VM for that matter. *sigh*
You should be able to do that with the RelocateVM method.
Specify the target datastore, but explicitely define the VMDK to stay where they are.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference