Solved

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

Posted on 2013-01-30
2
312 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
rhino JavaScript import, load 25 67
Powershell Script need assistance to make some changes 4 61
Python variable _ manually assigned 9 64
Message not shown 5 31
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

910 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

23 Experts available now in Live!

Get 1:1 Help Now