Saving the module

Ensure that you have saved the module to your Modules directory. You can locate the path using the following code:
($env:PSModulePath -split ';')[0]

Import the module

You can import the module using the following command:
Import-Module -Name PoshAsyncJob

Using PoshAsyncJob

Using Start-AsyncJob

Do not use ForEach/ForEach-Object or any other type of iteration with this function!
Doing so will cause each item in the collection to create its own runspacepool and will not allow for throttling of running jobs. This function has been designed to take pipeline input for the whole collection!

Some things to note:
  • This function takes input from the pipeline which is the main collection which will be thrown into a runspacepool for throttling.
  • The -Name parameter allows for a scriptblock to dynamically set the name to be whatever is being piped into the command.
  • The first parameter in the Param() statement will always be the item in the collection being passed into the command via the -InputObject parameter. The same goes if you use -InputObject named parameter instead.

Example 1
#Starting a job
1..10 | Start-AsyncJob -Name {$_} -ScriptBlock {Param($Item)$Item}

#Getting job status

#Receiving output from completed job
Get-AsyncJob -State Completed | Receive-AsyncJob

#Removing AsyncJob
Get-AsyncJob -State Completed | Remove-AsyncJob

Last edited Jun 28, 2014 at 4:11 AM by boeprox, version 2