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}}
Do i enter just the VM’s names in the CSV? If so, could you give an example?
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.
So run it as a scheduled task and use the Send-mailmessage cmdlet at the end, is that what you mean ?
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
}
———————————————————————————————————————-
Pingback: Cleaning your vCloud Director Thumbnails « Geek after Five
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!
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