This is a little flaky, but does work. YMMV...
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 | $prevJobs = {}.Invoke() While ($jobs = Get-StorageJob | Sort-Object Name) { $idGen = 0 $jobs | % { $jobObj = [PSCustomObject]@{ Name = $_.Name ProgId = $idGen++ UniqueId = $_.UniqueId Activity = ("Disk Operation: {0} [{1}]" -f $_.Name, $_.JobState) Complete = $false } if (($prevJobs | Where UniqueId -eq $jobObj.UniqueId).Count -eq 0){ $prevJobs.Add($jobObj) } Write-Progress -Id $jobObj.ProgId -Activity $jobObj.Activity -Status ("{0}% Complete:" -f $_.PercentComplete) -PercentComplete $_.PercentComplete } $prevJobs | Where Complete -eq $false | %{ if (-not ($jobs | Where UniqueId -eq $_.UniqueId)) { Write-Progress -Id $_.ProgId -Activity $_.Activity -Completed $_.Complete = $true } } Start-Sleep -Seconds 5 } |
No comments:
Post a Comment