Recently I had the need to do some SAN storage cleanup. We had VMs that were changed in regards to criticality and accordingly needed to be moved (storage vmotion) to different LUNs. In the environment I currently work in, storage has several tiers and it depends on the VM criticality where it fits in. As an example a development or test VM would be on different storage compared to a production server.
So, I received a list of VMs and LUNs involved for this project. Now I had 2 tasks to take care of. SVMotion the VMs to the new storage and then cleanup the old LUNs. At the same time it was decided to remove the old LUNs completely from the environment, so I had to make sure that the LUNs were indeed empty and cleaned out when handing them back to the storage team. This environment was built before I joined the company and for whatever reason the old VMWare Administrator and the storage team had decided to deploy “a gazillion” of mini LUNs.
However, manually moving random VMs between LUNs and checking a large number of LUNs by hand did not sound like very exciting to me. So, it was time to get Notepad++ out and to script these tasks where possible. PowerCLI is a great tool to take care of these tasks. Here are the scripts that I used to do the storage migrations.
Additional comments
I am running all storage vmotions in asynchronous mode and let the ESX/ESXi hosts work it out from there. Each host will only a certain number of migrations at the same time, which will result in a queue building up instead of flooding the SAN Fiber cards. I am also going Fiber to Fiber which gives me really nice through-put. I did not have to separate out VMDKs to different Vlans (fortunately), but I do have a script that would do that as well. Also, there are many ways to skin the cat. I am not saying this is the most elegant way to solve this problem, but the process as shown here has worked great for me.
The second script provides me with the disk capacity and free space information. All I do in Excel is then to compare and visit those LUNs that are not empty just yet.
Storage VMotion
# This script will do storage migrations for VMs listed inside the CSV file.
# The CVS file format would be as follows:
# column names: name,lun
# list per column: machine name,lun name
# This script will not do an advanced storage migration – meaning it will move a VM to a single LUN/volume.$vms = Import-Csv “C:\scripts\WorkArea\Storage\vmsomove.csv”
Disconnect-VIServer -Server * -Force
Connect-VIServer csgivmware -Protocol https -cred (Get-Credential) $cloneTask = foreach ($customer in $vms) { $vm = Get-VM $customer.name | Move-Vm -Datastore $customer.lun -RunAsync }
CSV File for Storage Migration
name,lun
vmserver1,newlunname01
vmserver2,newlunname02
vmserver3,newlunname03
Disk Space Script
$luns = Import-Csv “C:\scripts\workarea\storage\luns.csv”
$esxhost = Read-Host “Host Name as shown in vCenter”
$report = foreach ($customer in $luns) {get-vmhost $esxhost | Get-Datastore -name $customer.name | Select Name,CapacityGB,FreeSpaceGB }
$report | Export-Csv C:\scripts\workarea\storage\storagereport.csv -NoTypeInformation -UseCulture
CSV File LUNs
name
lun01
lun02
Leave a Reply