Function to convert VMs from thin to thick using #PowerCLI & #PowerShell

Written March 20th, 2012 by
Categories: Scripts, Virtualization
12 comments

Most people want to go from thick to thin to save space. I, on the other hand, want to convert my VMs from thin to thick. Thin provisioning buys you time, basically, but what do you do when you’re vastly over provisioned and your VMs are filling up available physical storage? Sure, you can manually go to each VM and use the GUI to migrate them and convert each one to thick. I had a couple hundred that were thin provisioned and needed them converted to thick.

I’ve been moving from 500GB LUNs to 1TB LUNs, so I scripted it out to migrate VMs over, as well as convert to thick using the New-Object cmdlet.


This is pretty basic, I didn’t put a lot of logic in it, as I had everything planned out already. You’ll need to change the ‘dest_datastore’ on line 2 for your destination datastore, and ‘src_datastore’ on line 4 to the source datastore.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
function thin2Thick{
    $dsView = Get-Datastore -Name "dest_datastore" | Get-View -Property Name
 
    $vms = Get-VM -Datastore src_datastore
 
    Foreach ($VM in $VMS){
        write-host -fore green `n`t "Migrating " $VM
        Get-VM $VM | % {
            $vmView = $_ | Get-View -Property Name
            $spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
            $spec.datastore =  $dsView.MoRef
            $spec.transform = "flat"
            $vmView.RelocateVM($spec, $null)
        }
        write-host -fore green `n`t "Finished migrating " $VM " Moving on..."
    }
}

This was done using the the API, and reference is here for relocation and here for transformation.

Tags: ,

// // // //

12 Responses to Function to convert VMs from thin to thick using #PowerCLI & #PowerShell

Leave a reply