Hi there,
after some fiddling around, I got it to work with the powershell background jobs (available at PowerShell V2 or higher).
The background job is waiting until all vMotion activities are done (1 or 8, doesn't matter).
Just pass your credentials in line 05 to 07, set the target datastore in line 08 and modify the command in line 14 to get the correct VMs.
To test the script, just add the -WhatIf parameter on line 32 after Move-VM.
# Load PowerCLI cmdlets Add-PSSnapin VMware.VimAutomation.Core -ErrorAction "SilentlyContinue" # Define vCenter User and target Datastore $vcHost = 'VC-HOSTNAME.DOMAIN.COM' $vcUser = 'user@domain.com' $vcPass = 'PASSWORD' $svmTarget = 'TARGET-DATASTORE' # Connect to vCenter Connect-VIServer $vcHost -User $vcUser -Password $vcPass # Get VMs (pass array of VMs to $VMs, for example 'get-datastore test | get-vm') $VMs = Get-ResourcePool "Tests" | Get-VM Foreach($VM in $VMs) { Write-Host ("Start Storage vMotion for VM '" + $VM.Name + "'") $Arguments = @{"vcHost" = $vcHost; "vcUser" = $vcUser; "vcPass" = $vcPass; "svmTarget" = $svmTarget; "VMId" = $VM.Id;} # Start Job $Job = Start-Job -ArgumentList $Arguments -ScriptBlock { param([Hashtable]$Data) # Load PowerCLI cmdlets Add-PSSnapin VMware.VimAutomation.Core -ErrorAction "SilentlyContinue" # Connect to vCenter Connect-VIServer $Data.vcHost -User $Data.vcUser -Password $Data.vcPass # Start SvMotion Get-VM -Id $Data.VMId | Move-VM -Datastore $Data.svmTarget return } Write-Host ("Waiting...") Wait-Job -Job $Job | Receive-Job Write-Host ("Storage vMotion for VM '" + $VM.Name + "' finished") }
Regards,
Emanuel