Quick and simple storage vMotion scripts

Here are a couple of quick storage vMotion scripts, easy enough but they come in useful when moving to a new datastore.

They will obviously be bound by the amount of concurrent sVMotions allowed for your version of ESX, the rest will queue until others have completed.

These are handy to fire off and walk away and then check later rather than having to manually kick each one off.

Option 1

Select the VMs on a certain datastore and move them to a new datastore and change the disk format to thin along the way

Get-Datastore "CurrentDatastoreName" | Get-VM | Move-VM -DiskStorageFormat Thin -Datastore "NewDatastoreName" –RunAsync

Option 2

Import a CSV with Name, NewDatastore headings and move each one of these converting the disk along the way

Import-Csv c:\Tmp\SvMotion.csv | Foreach {
    Get-VM $_.Name | Move-VM -DiskStorageFormat Thin -Datastore $_.NewDatastore -RunAsync
}

Did they move ?

To check these have completed successfully you can use the following:

Get-VM | Select Name, @{N="Datastore";E={$_ | Get-Datastore}}

7 thoughts on “Quick and simple storage vMotion scripts

  1. Ganesh

    Yes.

    Now i have fixed the issue to run the script from sechduel task, i just created a .cmd file and called ps script, It’s working fine,
    —————————————————————————————————
    C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe C:\ADMIN\ST\SVMOTION.ps1″
    ———————————————————————————————
    but still have problem sending mail.

  2. Ganesh

    I have a requriment to migrate the VM’s to new SAN box so i have created a small sVmotion Script to complete this task it’s working fine but i want to run this script in Schedule time also need to get Email with status once the job completed.

    Can someone pls help me.

    —————————————————————————————————————-

    $VIServer = Connect-VIServer VISERVER –user “USER” –Pass “XXXX” –Protocol Https

    $vms = Import-CSV C:\admin\ST\SVMotion1.csv

    foreach ($vm in $vms){

    Get-VM $vm.Name | Move-VM -Datastore $vm.TragetDatastore

    }

    ———————————————————————————————————————-

  3. Pingback: Cleaning your vCloud Director Thumbnails « Geek after Five

  4. mike C

    Hi Alan,
    Please ignore my previous post. I tested this and as long as you choose the datastore housing the vmx file, all partitions in the config will move to the new datastore.

    Thanks Again!

  5. mike C

    Hi Alan,
    Thanks for continueing to provide some valuble scripts!

    One question, how can I modify this storage vmotion script to account for a vm(s) that have partitions on mulitple datastores?

    –Mike C

Leave a Reply to mike C

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.