Write-Progress display - How to get rid of it when complete?

This seems straight forward, but I haven't seen/found the answer...

My progress bars hang around too long.  I would like them to go away when complete, but they don't always.

Typically the Write-Progress is within a loop, and it works.  Then imediately after the loop I add "Write-Progress -Complete", but that doesn't seem to do it.

What am I missing?


  • Edited by CBS3 Tuesday, December 13, 2011 12:39 AM
December 13th, 2011 3:37am

Please post a sample of one that doesn't work as expected and outline what it is you are hoping it will do.  
Free Windows Admin Tool Kit Click here and download it now
December 13th, 2011 9:00am

The loop and Write-Progress work fine.  The issue is that the completed status bar remains on the screen after completion.

 

#Some code...

While( -NOT $Script:RecordSetG.EoF )
{ #...Some code
 
 $intCounterL ++
 If( $intRecordCountL -gt 0 )
 { $dblPercentageL  = 100*( $intCounterL / $intRecordCountL )
  $intPercentageL  = [int]$dblPercentageL
  $intSecondsLeftL = ( $intRecordCountL - $intCounterL ) / 24
  Write-Progress           `
    -Activity         "Building mailbox objects..." `
    -PercentComplete  $intPercentageL    `
    -SecondsRemaining $intSecondsLeftL    `
    -CurrentOperation "$intPercentageL% complete" `
    -Status           "Please wait."
 }#End If
}#WEnd
Write-Progress -Completed

#...Some code

December 13th, 2011 6:44pm

I can't replicate your error.  When I run a progress bar in a loop, it disappears from the screen once the loop ends:

for ($i = 1; $i -le 100; $i++ ) 
      {write-progress -activity "Search in Progress" -status "$i% Complete:" -percentcomplete $i;Start-Sleep -Milliseconds 10}
    

Free Windows Admin Tool Kit Click here and download it now
December 13th, 2011 6:56pm

My initial thought is that you cll Write-Progress twice.  The first time has a different scope from the second.  So, I suspect the second instance is the issue.  Try commenting out the second one and set if the same issue persists.
December 13th, 2011 6:58pm

Not sure, but I don't think so...

There is only one instance of the write-progress cmdlet.  It executes many times within the loop.

Another question comes to mind... what is the -Completed argument for?  Should write-progress be called with that argument to close the display?  Or, when is that argument appropriate?

Free Windows Admin Tool Kit Click here and download it now
December 15th, 2011 12:39am

Not sure, but I don't think so...

There is only one instance of the write-progress cmdlet.  It executes many times within the loop.

Another question comes to mind... what is the -Completed argument for?  Should write-progress be called with that argument to close the display?  Or, when is that argument appropriate?

I see Write-Progress twice:

While( -NOT $Script:RecordSetG.EoF )
{ #...Some code
 
 $intCounterL ++
 If( $intRecordCountL -gt 0 )
 { $dblPercentageL  = 100*( $intCounterL / $intRecordCountL )
  $intPercentageL  = [int]$dblPercentageL
  $intSecondsLeftL = ( $intRecordCountL - $intCounterL ) / 24
  <em><strong>Write-Progress</strong></em>           `
    -Activity         "Building mailbox objects..." `
    -PercentComplete  $intPercentageL    `
    -SecondsRemaining $intSecondsLeftL    `
    -CurrentOperation "$intPercentageL% complete" `
    -Status           "Please wait."
 }#End If
}#WEnd
<em><strong>Write-Progress -Completed</strong></em>
I was suggesting eliminating the second one.

December 15th, 2011 4:10am

Experimenting with Write-Progress, it's a strange beast.

Try this on the command line by itself:

Write-Progress -Completed -Activity "Test"

You wil see that 'nothing' happens.  It has to be in a loop to stay on the screen.  That's what I find so strange about the OP's problem:  Maybe his loop in not ending?

Free Windows Admin Tool Kit Click here and download it now
December 15th, 2011 6:44am

But, if that were the case, would it ever reach the second Write-Progress?  To the OP, try adding a Write-Host (or Write-Output in the loop and outside the loop prior to your second Write-Progress to see if you ever make it that far.
December 15th, 2011 7:01am

The definition of the Completed switch:

-Completed [<SwitchParameter>]
 Indicates whether the progress bar is visible. If this parameter is omitted, Write-Progress displays progress information.

Demo: Try this to see the effect of using -completed:

while ($true) {
    Write-Progress -PercentComplete 50  -Activity "Testing"
    Start-Sleep 1
    Write-Progress -Completed -Activity "Testing"
    Start-Sleep 1
    } # end while

 

 

 

 

Free Windows Admin Tool Kit Click here and download it now
December 15th, 2011 7:28am

Not sure, but I don't think so...

There is only one instance of the write-progress cmdlet.  It executes many times within the loop.

Another question comes to mind... what is the -Completed argument for?  Should write-progress be called with that argument to close the display?  Or, when is that argument appropriate?

Hello CBS3,

Thanks for your posting.

As mentioned in document, "If this parameter is omitted, Write-Progress displays progress information."

You can also refer to the following links:

http://technet.microsoft.com/en-us/library/dd347663.aspx

Hope this helps, and any questions or confusion please let us know.

 

Regards,

Anders Wang

December 15th, 2011 9:40am

This is basically what the original code snippet was.  Originally there was only the single Write-Progress instance (within the loop).  Processing definitely completes within the loop and progresses beyond.

I added the second call to Write-Progress, with the -Completed switch, hoping that would "turn it off."

I also tried using the ID parameter in both instances of the command hoping to clarify the instance reference.

Free Windows Admin Tool Kit Click here and download it now
December 16th, 2011 12:52am

This is basically what the original code snippet was.  Originally there was only the single Write-Progress instance (within the loop).  Processing definitely completes within the loop and progresses beyond.

I added the second call to Write-Progress, with the -Completed switch, hoping that would "turn it off."

I also tried using the ID parameter in both instances of the command hoping to clarify the instance reference.


Hi CBS3,

 

My initial thought is that the While statement is still running.

 

I did a lot of testing, but still can’t reproduce your error. Could you upload a screenshot about that error? Thus we can further discuss about this case.

 

Thanks.

Anders Wang

December 19th, 2011 11:19am

I can't replicate your error.  When I run a progress bar in a loop, it disappears from the screen once the loop ends:

for ($i = 1; $i -le 100; $i++ ) 
      {write-progress -activity "Search in Progress" -status "$i% Complete:" -percentcomplete $i;Start-Sleep -Milliseconds 10}
    
Free Windows Admin Tool Kit Click here and download it now
April 19th, 2012 5:29pm

After your code where you use the write-progress use:
Write-Progress -Activity "<same as your progress bar>" -Status "Ready" -Completed

  • Proposed as answer by JustusIV 13 hours 58 minutes ago
October 18th, 2013 5:09pm

After your code where you use the write-progress use:
Write-Progress -Activity "<same as your progress bar>" -Status "Ready" -Completed

  • Proposed as answer by JustusIV 14 hours 5 minutes ago
Free Windows Admin Tool Kit Click here and download it now
October 18th, 2013 5:09pm

After your code where you use the write-progress use:
Write-Progress -Activity "<same as your progress bar>" -Status "Ready" -Completed

  • Proposed as answer by JustusIV Friday, March 21, 2014 8:27 PM
October 18th, 2013 5:09pm

After your code where you use the write-progress use:
Write-Progress -Activity "<same as your progress bar>" -Status "Ready" -Completed

I was having this issue and this solved it for me.
Thank you.
Free Windows Admin Tool Kit Click here and download it now
March 21st, 2014 4:33pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics