ESXi

 View Only
Expand all | Collapse all

Script to convert 100+ servers from Thick to Thin Format

  • 1.  Script to convert 100+ servers from Thick to Thin Format

    Posted May 28, 2015 06:12 AM

    Hi All,

    I know there is an option to convert a VM from Thick to Thin format through GUI. But sad part is we have to keep an eye on the progress , datastore and all.

    I have 100's+ of VMs which are in Thick format disk , i want to convert all those VM's in Thin format without any downtime.

    I have the list of all the VM's looking for some script which by taking the VM names from text or excel can do migrate thick HDD to Thin.

    Thanks in advance.



  • 2.  RE: Script to convert 100+ servers from Thick to Thin Format

    Posted May 28, 2015 06:21 AM

    This will require a svMotion or a disk clone.

    Do you have sufficient spare datastore capacity ?



  • 3.  RE: Script to convert 100+ servers from Thick to Thin Format

    Posted May 28, 2015 06:25 AM

    Yes i have a sufficient space in datastore.

    Diskclone? will it create a new copy of Disk and later we have to delete it .



  • 4.  RE: Script to convert 100+ servers from Thick to Thin Format

    Posted May 28, 2015 06:28 AM

    That is one option, the other one is to svMotion the VM (with Move-VM).

    You can specify the new DiskStorageFormat on the cmdlet.



  • 5.  RE: Script to convert 100+ servers from Thick to Thin Format

    Posted May 28, 2015 06:32 AM

    Bit confused :smileyconfused:

    can i get the script line, like get-content (i will put vm list in txt or excel) and move it to Thin format.



  • 6.  RE: Script to convert 100+ servers from Thick to Thin Format

    Posted May 28, 2015 06:45 AM

    I don't know your environment, but would the following be an acceptable scenario ?

    • Get the VMs you want to convert from a Datasrore1
    • Move (svMotion) all these VMs, that have Thick vdisks, to datastore Datastore2. During the svMotion convert the vdisks from Thick to Thin
    • Optional: move (svMotion) the VMs back to the orginal Datastore1
    • Repeat the above for all datastores

    This of requires the presence of Datastore2, with sufficient capacity to store the VMs.

    As you can see, the scenario to be used depends on your environment.

    Is there a Datastore2 available ?

    Can it host (temporarily) all the VMs from Datastore1 ?

    Do the VMs need to go back to the original datastore ?



  • 7.  RE: Script to convert 100+ servers from Thick to Thin Format

    Posted May 28, 2015 06:49 AM
    • Move (svMotion) all these VMs, that have Thick vdisks, to datastore Datastore2. During the svMotion convert the vdisks from Thick to Thin

    This option will suit for my VM environment.



  • 8.  RE: Script to convert 100+ servers from Thick to Thin Format

    Posted May 28, 2015 07:10 AM

    You could do something like this

    $vmNames = Get-Content .\vmnames.txt

    $ds1Name = 'datastore1'

    $ds2Name = 'datastore2'

    $convertedVMs = Get-VM -Name $vmNames -Datastore $dsName -ErrorAction SilentlyContinue |

    Move-VM -DiskStorageFormat Thin -Datastore $ds2Name -Confirm:$false

    Move-VM -VM $convertedVMs -Datastore $ds1Name -Confirm:$false

    The 2nd Move-VM svMotions the converted VMs back to the original datastore.

    You will have to repeat this for each datastore that holds VMs with Thick vdisks



  • 9.  RE: Script to convert 100+ servers from Thick to Thin Format

    Posted May 28, 2015 09:01 AM

    Thanks LucD for your quick help :smileyhappy:.

    The script was good but the moving the vm back to its original datastore seems to be double work.

    I have got below given script lines, which will move the VM one at a time from one datastore to another and convert to thin.

    Connect-viserver vcenter.domain.tld

    $sourcedatastore = “SOURCEDATASTORE“

    $destinationdatastore = “DESTINATIONDATASTORE“

    $vms = Get-VM -Datastore $sourcedatastore

    foreach($vm in $vms){

    Move-VM -VM (Get-VM -Name $vm) -Datastore $destinationdatastore -DiskStorageFormat thin

    }


    But the problem is the above script will move all the VM's from "sourcedatastore" to "destinationdatastore" no matter it is Thin or Thick to Thin format in destination datastore, These will un-neccessarily create network traffic for the VM's which are already in Thin format.


    Can we do something with above script , it should select only the VMs which are in Thick format from sourcedatastore and convert to Thin in DestinationDatastore.



    Thanks LucD for all your helps.. :smileyhappy:



  • 10.  RE: Script to convert 100+ servers from Thick to Thin Format
    Best Answer

    Posted May 28, 2015 12:19 PM

    Try like this, it will only select VMs that have at least 1 Thick vdisk.

    Connect-viserver vcenter.domain.tld

    $sourcedatastore = “SOURCEDATASTORE“

    $destinationdatastore = “DESTINATIONDATASTORE“

    $vms = Get-VM -Datastore $sourcedatastore | where{(Get-HardDisk -VM $_ ).StorageFormat -contains 'Thick'}

    foreach($vm in $vms){

      Move-VM -VM (Get-VM -Name $vm) -Datastore $destinationdatastore -DiskStorageFormat thin

    }



  • 11.  RE: Script to convert 100+ servers from Thick to Thin Format

    Posted Jun 01, 2015 02:37 AM

    LucD You are the real Man... :smileyhappy::smileyblush:

    Above given script worked like charm.. Awesome LucD.. I have seen your all efforts helping on VMware PowerCLi forum is Commendable, Appreciable.

    Hats off to you. :smileycool:

    Connect-viserver vcenter.domain.tld

    $sourcedatastore = “SOURCEDATASTORE“

    $destinationdatastore = “DESTINATIONDATASTORE“

    $vms = Get-VM -Datastore $sourcedatastore | where{(Get-HardDisk -VM $_ ).StorageFormat -contains 'Thick'}

    foreach($vm in $vms){

      Move-VM -VM (Get-VM -Name $vm) -Datastore $destinationdatastore -DiskStorageFormat thin

    }



  • 12.  RE: Script to convert 100+ servers from Thick to Thin Format

    Posted Jan 07, 2016 09:16 AM

    Hi Raju ,

    My requirement is a bit similar to yours , however I need move a list a VM's from a specific cluster from Thick to Thin.

    Note : There are other VM's part of that cluster as well which remains to be untouched.

    A script for this would be really handy.

    Thanks in Advance.

    Regards ,

    Shivam