2

Some of the PowerShell commands in my script use progress bars, and those progress bars keep hanging around long after the command has finished. How do I get them to go away?

For example, save the following three lines as a .ps1 script, then run it from the command line. As the window scrolls from the directory listing, a ghost image of the progress bar from the completed command flashes in and out.

$ready = Read-Host "Press Return to Start. Press Control-C anytime to exit."
Test-NetConnection localhost
if ($?) { dir -Path C:\Windows -Recurse -File }

Picture of the ghost progress bar

What do I need to add between the Test-NetConnection command and the dir command that will make that ghost progress bar disappear?

Marc
  • 23
  • 1
  • 3
  • [You may find this post helpful](https://stackoverflow.com/questions/46214143/suppress-information-of-test-netconnection) – G42 Apr 05 '18 at 20:06
  • Thanks. Unfortunately, `Test-NetConnection` was just an example I thought would show the problem. Turns out that the Exchange Server PowerShell cmdlets do the same thing, e.g. `Add-DatabaseAvailabilityGroupServer` is what ails me. – Marc Apr 05 '18 at 21:10

1 Answers1

6

seems to help:

$ready = Read-Host "Press Return to Start. Press Control-C anytime to exit."
Test-NetConnection localhost
Write-Progress -Completed -Activity "make progress bar dissapear"
if ($?) { dir -Path C:\Windows -Recurse -File }
  • Works great for `Test-NetConnection`, thank you! But, when I put it into my script, I found that it had no effect for the Exchange Server PowerShell cmdlets. :-( – Marc Apr 05 '18 at 21:07