rxjoseph
Enthusiast
Enthusiast

How to start two storage vmotion at same time

Jump to solution

Hi LucD

I have the below script which runs perfect, however i have around 2000 VMs to storage migrate and with this method it works great but only one storage vmotions starts at any given time and it waits until the task is completed to start the next task. This works but takes more than double the time to complete

I would like to know how can i start 2 or more storage vMotion task at the same time

 

Thanks for your help as always

RXJ

 

#Select the CSV file

$VMdetails = Get-Content -path $TemplateCSVfile |Select-String '^[^#]' | ConvertFrom-Csv -UseCulture

Write-Host "Processing ..................................." -ForegroundColor White


#############################################################################################
# #
#*********************************KICK OFF THE MIGRATION*********************************#
# #
# #
#############################################################################################

##################################################
## Search the VM to be migrated and validate VM ##
## if found else skip to next record on the CSV ##
##################################################

Foreach ($VMdetail in $VMdetails) {

$VM = Get-VM -Name $VMdetail.VMNAME -ErrorAction SilentlyContinue


If ($VM) {
Write-Host "VM is a alive on the source VC..." -ForegroundColor green $VM
}
Else {
Write-Host 'VM' $VMdetail.VMNAME' Cannot be found' -ForegroundColor Magenta
continue
}

#}




##############################################################
## Check if the destination Datastore is available if found ##
## Proceed , if unavailable skip to the next record ##
##############################################################

 

$destinationDatastore = Get-Datastore $VMdetail.TgDatastore -ErrorAction SilentlyContinue

if ($destinationDatastore) {

Write-Host "VM will be moved to following datastore... " -ForegroundColor Green $destinationDatastore
}
Else {

Write-Host " Destination datastore not found" -ForegroundColor Magenta
Continue
}

#}

#################################################################################
## Move-VM does the actual move of the VM provided all of the above checks are ##
## Satisfied and completes the migration. ##
#################################################################################



Move-VM -vm $VM -Datastore $destinationDatastore | out-null -ErrorVariable $movevmerr
if ($movevmerr -eq $null ) {
Write-host " VM migration in progress ........." -ForegroundColor Cyan
}
Else {
Write-Host " Move-VM error $movevmerr"
continue
}



}

 


############################################
## Display VM information after Migration ##
############################################


Get-VM $VMdetails.VMNAME -ErrorAction SilentlyContinue | Get-NetworkAdapter |

Select-Object @{N="VM Name";E={$_.Parent.Name}},

@{N="Cluster";E={Get-Cluster -VM $_.Parent}},

@{N="ESXi Host";E={Get-VMHost -VM $_.Parent}},

@{N="Datastore";E={Get-Datastore -VM $_.Parent}},

@{N="Network";E={$_.NetworkName}} | Format-List

 

Labels (1)
  • e

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

If you start them all with RunAsync, it could indeed overload your environment.

Other users mostly set a limit to how many such background tasks can run in the background.
Once the limit is reached, you wait in a loop till one or more tasks are complete.
Then you start another bunch, up to the limit.

There are several threads in this community that provide solutions for such a concept.


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

View solution in original post

4 Replies
LucD
Leadership
Leadership

You can use the RunAsync switch.
This starts the task in the background, and the cmdlet returns immediately. 


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

Tags (1)
rxjoseph
Enthusiast
Enthusiast

Hi LucD

I have a CSV with 2000 VMs and with the "RunAsync switch" will it kick off all the 2000 VM migration at one time ? as it could bring down the network ? or how many task will it execute at any given time ?

Please advise

RXJ

 

0 Kudos
LucD
Leadership
Leadership

If you start them all with RunAsync, it could indeed overload your environment.

Other users mostly set a limit to how many such background tasks can run in the background.
Once the limit is reached, you wait in a loop till one or more tasks are complete.
Then you start another bunch, up to the limit.

There are several threads in this community that provide solutions for such a concept.


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

View solution in original post

rxjoseph
Enthusiast
Enthusiast

Hi LucD

Thanks for your update and this helps with where we stand on the storage migration

Many thanks

RXJ

0 Kudos