VMware Cloud Community
tdubb123
Expert
Expert

storage vmotions over 10 VMs

when i run this, I think limit is only 10 svmotions at one time? 

 

get-datastore -name (ds1) | get-vm | move-vm -datastore (get-datastore -name ds2) -runasync

how do I loops it so it continues after 10vms

0 Kudos
9 Replies
LucD
Leadership
Leadership

The number of parallel svMotion is indeed limited, but the other ones should be queued and run in the end.
Do you see differently?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
tdubb123
Expert
Expert

yes it does. I wanted to ad a progress bar to it

0 Kudos
LucD
Leadership
Leadership

What kind of progress bar?
One for each of the background tasks, or one for all the tasks?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
tdubb123
Expert
Expert

actually can i do something like this for multiple ds

 

Import-Csv "C:\scripts\dsmigration.csv" -UseCulture | % {

 

$old_ds = $_.old_ds

$new_ds = $_.new_ds

$VMs = get-vm -Datastore $old_ds

$VMs | move-vm -Datastore $new_ds -RunAsync

}

 

 

my csv file is

old_ds,new_ds

ds1,ds10

ds2,ds11

etc...

0 Kudos
LucD
Leadership
Leadership

Yes, that should work


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
tdubb123
Expert
Expert

do i need a for loop for this to work on multiple ds? and can i add a progress bar per vm?

0 Kudos
LucD
Leadership
Leadership

Your sample code has a loop after the Import-Csv.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
tdubb123
Expert
Expert

yes. 

 

also trying to dismount all isos before proceeding

 

Import-Csv "C:\scripts\dsmigration.csv" -UseCulture | % {

 

$old_ds = $_.old_ds

$new_ds = $_.new_ds

$VMs = get-vm -Datastore $old_ds

 

# Check is any iso mounted on vms

 

foreach ($vm in $VMs) {

    if ((Get-VM $vm | Get-CDDrive).isopath -ne $null)

    $vm | get-cddrive | Set-CDDrive -NoMedia -Confirm:$False

}

else

 

#foreach ($vm in VMs){

#    movevm -datastore $new_ds -DiskStorageFormat Thin -RunAsync

$VMs | move-vm -Datastore $new_ds -DiskStorageFormat Thin -RunAsync

 

}

 

 

do i have to do it one at a time for the isomount dismount? 

0 Kudos
LucD
Leadership
Leadership

You could do something like this

Import-Csv "C:\scripts\dsmigration.csv" -UseCulture -PipelineVariable row | 
ForEach-Object -Process {
    Get-VM -Datastore $row.old_ds |
    ForEach-Object -Process {
        Get-CDDrive -VM $_ | where{$_.IsoPath} | Set-CDDrive -NoMedia -Confirm:$false
        Move-VM -Datastore $row.new_ds -DiskStorageFormat Thin -RunAsync
    }
}    
     


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos