Execute a scriptblock in parallel using runspaces taking pipeline input.
Utils\Invoke-Parallel.ps1
Invoke-Parallel [-Pipeline] <Object> [-ScriptBlock <Object>]
[-DictParamList <System.Collections.Generic.Dictionary`2[System.String,System.Object]>] [-Module <Object>]
[-ThrottleLimit <Object>]
This is based on Tobias Weltner's excellent Efficient PowerShell online presentation
$params=New-Object 'system.collections.generic.dictionary[string,object]'
$params.Add("multi",2)
1..10 | Invoke-Parallel -scriptBlock {$_* $multi} -dictParamList $params
$sb={param($num) ("$num :this is a quite long text.`n" * ($num*500)) | set-content -Path "c:\$num.txt"}
1..10 | Loop-Parallel -scriptblock $sb
pipeline element should be first function parameter for the function to execute in parallel
The input to execute the scriptblock against in parallel.
Type: Object
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: FalseThe code to execute in paralllel.
Type: Object
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseParameters passed and referenced by the scriptblock should be of type [system.collections.generic.dictionary[string,object]].
Type: System.Collections.Generic.Dictionary`2[System.String,System.Object]
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseModule(s) to be imported so that they can be referenced by the code in the scriptblock.
Type: Object
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: FalseNumber of parallel runspaces to use.
Type: Object
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: 10
Accept pipeline input: False
Accept wildcard characters: False