Sunday, June 8, 2014

Storage vMotion just one hard disk using PowerCLI

I was looking for a quick way to storage vMotion some of a VMs hard disks but not all of them. I found a pretty quick one-liner at ict-freak.nl
Get-HardDisk -vm | Where {$_.Name -eq "Hard disk <#>"} | `
% {Set-HardDisk -HardDisk $_ -Datastore "" -Confirm:$false}
However, I found that Set-HardDisk is deprecated. Move-HardDisk is the preferred method. The help file for Move-Hard disk had some simple examples.
$vm = get-vm "MyVM"
$mydisk = $vm | get-harddisk -name "Hard Disk 3"
$mydatastore = get-datastore -name "SAN2"
move-harddisk -harddisk $mydisk -datastore $mydatastore


These can be combined into a one-liner like so:
Move-HardDisk -harddisk (get-vm "MyVM" | get-harddisk -name "Hard Disk 3") `
-datastore (get-datastore -name "SAN2") -confirm:$false -runasync

Worked perfectly for me.

No comments:

Post a Comment