Common/Public/Receive-RunspaceJob.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function Receive-RunspaceJob
{
    [CmdletBinding()]
    param
    (
        [Parameter(ValueFromPipeline)]
        [object[]]
        $RunspaceJob
    )

    process
    {
        while ($RunspaceJob.Handle.IsCompleted -contains $false)
        {
            Start-Sleep -Milliseconds 100
        }

        foreach ($job in $RunspaceJob)
        {
            $job.Shell.EndInvoke($job.handle)    
            $job.Shell.Dispose()    
        }
    }
}