Powershell – scripted Storage Migration of SCVMM VMs

Those of you that work with SCVMM 2012 R2 know storage migrations aren’t as straightforward from the GUI as they should’ve been. Assuming you are a VMware person like me and simple tasks like these should be, well, simple..? Given my propensity to PowerShell everything these days (as you should be doing too, IMO), here’s a quick one I did. I found it’s best to move them VMs cluster-by-cluster for three reasons. 1. You don’t kick off too many in one go and possibly choke your host(s). 2. There are usually limits set on the number of Storage Migrations you do via VMM (usually 5 or 10?). 3. In my case, each cluster had volume1, volume2, volume3 etc as the name of the CSVs.


$Cluster = Read-Host -Prompt 'Please enter Cluster FQDN'
$ClusterVMs = Get-SCVirtualMachine | Where {$_.vmhost.hostcluster.name -eq "$Cluster"}

# Filtering out volumes and selecting volume1 only and selecting 10 machines only at one time

$VMsonPurevol1 = $ClusterVMs | ? {$_.DiskResources -match "volume1"} | select -First 10
# Moving VMs from their current location to volume6 using some optimization switches
foreach ($VM in $VMsonPurevol1){Move-SCVirtualMachine -VM $VM -VMHost $VM.HostName -Path C:\ClusterStorage\Volume6 -UseLAN -RunAsynchronously -UseDiffDiskOptimization}

 

2 Comments

 Add your comment
  1. Great article. Thank you so much for this interesting and well-written article. You show the Storage Migration of SCVMM VMs though Powershell. Is this mandatory each cluster volumes as the name of CSVs ?
    Thanks for sharing.

Leave a Comment

Your email address will not be published.