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.
I’m curious, why not pass parameters and use the Move-VM cmdlet?
# Script MigrateDatastores_and_ConvertVMsToThick.ps1
param($SourceDST,$TargetDST)
Get-VM -Datastore $SourceDST | % {
Move-VM $_ -Datastore $TargetDST -DiskStorageFormat Thick
#Might need to add “-Confirm:$false”, I don’t recall
}
Optional
————–
Should test for valid datastores
Could test that target datastore has sufficient free space
Could test that the source datastore is empty after migration.
Additionally, if you pass parameters into the datastore migration script, you can automate that. Create a two column CSV with the source and target datastores, and then loop that into the migration script.
Import-Csv .\DatastoresToMigrate.csv | % { .\MigrateDatastores_and_ConvertVMsToThick.ps1 $_.Source $_.Target }
Caution: Code not tested, written off the top of my head. There might be typos/bugs.
When I wrote this, I was still on vCenter 4.1, and, at that time, it required the VM to be off. Maybe I’m wrong, but I tested different ways and they all required the VM to be off.
What you posted will work, too, and I don’t think you need the confirm:$false. Shows there are more than one way to skin a cat :D
I didn’t consider it might not be possible to convert a powered on VM to thick. When vSphere 4 came out we converted over 1000 VMs to thin by script, all powered on. We’ve save so much disk space I can’t imaging using thick VMs. I’m still using PowerCLI v4.1 (haven’t gotten around to upgrading), but I only have vSphere 5 environments to test with. I did confirm you can convert a powered on VM from thin to thick with PowerCLI v4.1 and vSphere 5.
Interesting. I know it wasn’t as far back as 3.5, but might have actually been 4.0. I still have a few lingering 4.0 hosts, which might have been the issue. At least now readers have multiple ways to convert from thin to thick!
Finally got around to looking into this, and apparently I was referencing inflating the hard disk while it was on (which you cannot do). You can only inflate (convert to thick) during storage vMotion.
Luke,
I am currently looking for a PowerCLI script that convert VM’s from thin to thick, I have a pretty big environment, but I do not want to do it manually (one by one), could you provide a script that could help me to accomplish my goal?
Thanks,
I can certainly help. Email me, [email protected] and we’ll get something going.
Luke,
I did sent you an e-mail with my request, please confirmed if you received the message.
Thanks,
Luke,
Sorry for not commenting before, but I would like to say thank you very much, the script works as expected (like a champ) very handy if you are planning to migrate a batch of VM’s from thin to thick with a progress bar and copy function status.
Thank you very much
Glad I could help! Here’s the post with the script I slapped together for you: http://thephuck.com/virtualization/reader-request-scripted-vm-conversion-to-thick-from-input-csv-file-using-powercli/