Created
May 1, 2014 21:17
-
-
Save anonymous/3ad9e4e741c2fd274c86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scriptblock = { | |
$repetitions = 10 | |
for($i = 1; $i -le $repetitions; $i++) | |
{ | |
#The work is currently simulated by sleeping | |
Start-Sleep -Seconds 2 | |
#Write some information about how far we have come | |
Write-Output @{ | |
Message = "We're at step $i" | |
PercentComplete = ($i * 100 / $repetitions) | |
} | |
} | |
} | |
$job = Start-Job $scriptblock | |
#This implementation does not work if the job goes to "Failed" state or other error state | |
while($job.State -ne "Completed" -or $job.HasMoreData) | |
{ | |
#This implementation does not sum all work, instead takes only the last output information | |
$output = $job | Receive-Job | Select -Last 1 | |
if ($output) | |
{ | |
$progressInfo = @{ | |
Activity = "Work" | |
Status = "Working" | |
PercentComplete = $output.PercentComplete | |
CurrentOperation = $output.Message | |
} | |
Write-Progress @progressInfo | |
} | |
Start-Sleep -Seconds 1 | |
} | |
Write-Progress -Activity "Work" -Completed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment