Afternoon all,
I’m using this function provided by Santiago Squarzon Add Write-Progress to Get-Job/Wait-Job
I’m looking to change the progress bar to SecondsRemaining based off the $Timeout
value
Below is the Write-Progress snippet from the full function.
using namespace System.Collections.Generic
using namespace System.Diagnostics
using namespace System.Threading
using namespace System.Management.Automation
function Wait-JobWithProgress {
[cmdletbinding()]
param(
[parameter(Mandatory, ValueFromPipeline)]
[Job[]] $InputObject,
[parameter()]
[double] $TimeOut
)
begin {
$timer = [Stopwatch]::StartNew()
$jobs = [List[Job]]::new()
}
process {
foreach($job in $InputObject) {
$jobs.Add($job)
}
}
end {
$total = $jobs.Count
$completed = 0
$expression = { $true }
if($PSBoundParameters.ContainsKey('TimeOut')) {
$expression = { $timer.Elapsed.TotalSeconds -le $TimeOut }
}
while((& $expression) -and $jobs) {
$status = “running job. Timeout in $($timeout / 60) minutes”
$progress = @{
Activity = 'Waiting for Jobs'
SecondsRemaining = #this is where I’m stuck
Status = $status
}
Write-Progress @progress
I’m stuck on how to get the math to properly work for counting down based off the $timeout
value.
An example command is
Start-Job {sleep -s 60} | Wait-JobWithProgress -Timeout 120