How to replace an old Hyper-V CSV Storage with new one via PowerShell?
Posted in Windows Powershell, Windows Server | No Comment | 2,000 views | 04/07/2014 18:00
Lets assume that you have a 3 years old storage and you are using it to place your virtual machines on Hyper-V Cluster. Then you bought a new storage box, you created LUNs on it and assign them as a CSV volumes on your existing Hyper-V Cluster. So next achievement would be migrating your virtual machines from old storage to new one.
Update: This script is now a function called Start-CSVMigration, you can reach it from:
That migration could be a headache if you have many VMs and many storage LUNs. So in that case, you can use following script to migrate Virtual Machines per CSV Volume. Just you need to specify which CSV volume you would like to drain. So let’s assume that volume is Volume1. I will specify that volume by following line:
Now you need to specify other CSV Luns as well to filter them. Otherwise, you can migrate a VM to old storage again. So we are filtering them by following lines:
We are creating an array called FilteredVolumes then adding our old storage luns to this array. You will see that I’m also adding $TargetVolume to same array. Because there is a chance to try to migrate a VM to same volume. So that will prevent that kind of issues.
So how can I get destination volume?
As you can notice from the code below, i’m getting all CSV volumes, filtering old storage volumes, sorting new storage CSVs by their free space and selecting the storage which has biggest available disk space.
So I’ll place VM into that volume:
If you get the idea, now I can share full script:
It’s enough to run this script on one of the Cluster Node, so that will start migrating virtual machines. That will also give an output, so you will be able to see which VM you are migrating. I hope you will find it useful. See you!
Tags: cluster shared volumes, drain CSV, migrate VMs, replace Hyper-V CSV storage, retire old CSV storage
Leave a Reply