Solved

Will these powercli commands wait to happen or will they execute at the same time?

Posted on 2013-01-30
2
311 Views
Last Modified: 2013-02-01
I have a simple script to move (Svmotion) some VMs - eg;

Get-VM “MyVM1“ |Move-VM -datastore (Get-datastore “MyDatastore1“)
Get-VM “MyVM2“ |Move-VM -datastore (Get-datastore “MyDatastore2“)
Get-VM “MyVM3“ |Move-VM -datastore (Get-datastore “MyDatastore3“)
Get-VM “MyVM4“ |Move-VM -datastore (Get-datastore “MyDatastore4“)

Open in new window


Will these powercli commands wait to happen or will they execute at the same time? What would I do to get them to execute at the same time?
0
Comment
Question by:Thaidog
2 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 38837383
use background jobs:
$vm_list = "vm1","vm2","vm3"
$ds_list = "ds1","ds2","ds3"

for($i=0;$i<$vm.list.Length;$i++)
  # Define what each job does
  $ScriptBlock = {
Get-VM $vm_list[$i] |Move-VM -datastore (Get-datastore $ds_list[$i])
Start-Sleep 60
  }

  # Execute the jobs in parallel
  Start-Job $ScriptBlock
}

Get-Job

# Wait for it all to complete
While (Get-Job -State "Running")
{
  Start-Sleep 10
}

# Getting the information back from the jobs
Get-Job | Receive-Job

Open in new window

0
 
LVL 5

Expert Comment

by:coraxal
ID: 38837432
@sedgwick - when you work with jobs, are those jobs processed by the local machine, or the remote machines? If by remote machines, do they have to have powershell? same version of powershell?
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now