views:

579

answers:

3

Say i have cmdlet1 and cmdlet2, both are long running tasks. Normally i would have a batch file which calls the two cmdlets in order:

call powershell cmdlet1
call powershell cmdlet2

Is there anyway to set them off asynchronously?

A: 

Try:

cmd.exe /c call powershell cmdlet1
cmd.exe /c call powershell cmdlet2
Noon Silk
Those will still be executed in the current console window one after another. `cmd /c start powershell cmdlet1` works, though.
Joey
+5  A: 

If you're on PowerShell 2, you can use background jobs.

From the help:

about_Jobs

When you start a background job, the command prompt returns immediately, even if the job takes an extended time to complete. You can continue to work in the session without interruption while the job runs.

So you can use

Start-Job -ScriptBlock { cmdlet1 }
Start-Job -ScriptBlock { cmdlet2 }

However, you need to have PowerShell configured for remoting, even when running a job locally.

I also stumbled over this:

Joey
A: 

If you have to stay on v1, try seeing if you can use the PSEventing snap-in: http://pseventing.codeplex.com/

schellack