Public/Get-DTJobLatestOutput.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 26 27 28 29 30 31 32 33 34 35 |
<#
.SYNOPSIS Returns the latest output of a job in a thread-safe way. .DESCRIPTION Returns the latest output of a job in a thread-safe way. It returns immediately without waiting for the job output. It returns $null if the job has never returned an output. .PARAMETER InputObject Job object to get the output. .INPUTS PSCustomObject that represents a job object. .OUTPUTS Objects returned by the job's ScriptBlock. .EXAMPLE $job = Start-DTJobBackgroundThreadTimer -ScriptBlock {Invoke-RestMethod https://wttr.in/?format="%c%t\n"} -IntervalMilliseconds 60000 $weather = Get-DTJobLatestOutput $job #> function Get-DTJobLatestOutput { param ( [Parameter(Mandatory=$true, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)] [PSCustomObject]$InputObject ) process { $InputObject.Sync.output } } |