Note that there are some explanatory texts on larger screens.

plurals
  1. POCustom powershell cmdlets do not support multi-threading?
    primarykey
    data
    text
    <p>In the code blocks below, I'm trying to run Get-MyCmdlet in 3 separate threads, each of which opens a google page if the Get-MyCmdlet did not give anything.</p> <p>The Get-MyCmdlet is fairly simple, the only thing it does is WriteObject("hello world"); (defined in the c# code).</p> <p>However the script always opens up a google page, unless I change the Get-MyCmdlet to Get-Host(which is a system default cmdlet). </p> <p>Is it because the custom cmdlets are not supporting multi-threading? Any help will be greatly appreciated!</p> <p>The cmdlet: </p> <pre><code>[Cmdlet(VerbsCommon.Get, "MyCmdlet ")] public class GetMyCmdlet : Cmdlet { protected override void ProcessRecord() { WriteObject("hello world"); } } </code></pre> <p>the script:</p> <pre><code>$ScriptBlock = { $result = Get-MyCmdlet if (!$result) {[System.Diagnostics.Process]::Start("http://www.google.com")} $name = ($result | get-member)[-1].name $result = $result.$name return $result } </code></pre> <p>....</p> <pre><code>$threads = 3 for ($i = 0; $i -lt $threads) { $running = @($jobs | Where-Object {$_.State -match 'Running'}) Write-Host $running.length if ($running.length -lt $threads) { $jobs += Start-job -ScriptBlock $ScriptBlock $i = $i + 1 } else { get-job | receive-job $finished = @($jobs | Where-Object ($_.State -match 'Completed')) if ($finished) { $finished.getType() foreach($job in $finished) { Receive-Job -keep $job | Out-File "Output$.txt" $i = $i + 1 $finished.Remove($job) Remove-Job -job $job } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload