Move VM Storage

I need to move storage for a large number of VMs. The powershell for a single VM is simple “Move-VMStorage VM1 -DestinationStoragePath C:\ClusterStorage\Hyper-V\VMName”. However, i have too many VMs to move. So to move all, i would like to fetch several VMs based on a condition “Get-VM | where {$_.path -like ‘D:\OldPath’}”, and then pipe the results (or ForEach) to a Move-VMStorage, and using the VMname as the folder name. So for example, if the VM name is “VM1”, then the command should be “Move-VMStorage VM1 -DestinationStoragePath C:\ClusterStorage\Hyper-V\VM1”. I just cant figure out this simple task…

I also need to make sure that it wont cycle to next one before completing the previous one (else ill chock the storage network)

 

Instead of coding it for you, how about you share the code you’ve written so far?

Ok i think i figured it out, the one below seems to work.

Get-ClusterGroup | where {$_.grouptype -like 'VirtualMachine'} | get-vm | where {$_.path -like '*SLnet*'} | foreach {Move-VMStorage ($_.name) -DestinationStoragePath C:\ClusterStorage\EduranceStorage\Hyper-V\$($_.name)}