Solved

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

Posted on 2013-01-30
2
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

617 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