Write-Progress with Write-Output

Welcome Forums General PowerShell Q&A Write-Progress with Write-Output

  • This topic has 1 reply, 2 voices, and was last updated 1 month ago by
    Moderator
    .
Viewing 1 reply thread
  • Author
    Posts
    • #195053
      Participant
      Topics: 2
      Replies: 0
      Points: 25
      Rank: Member

      Hi,

      I'm using Write-Progress along with Write-Output. The latter is causing Write-Progress to flicker/blink.

      If I take out the Write-Output line the flickering/blinking goes away.

      function Write-Log([string]$Text, [boolean]$Screen, [boolean]$File, [string]$Color = ("White")) {
      
          $defaultcolor = $host.UI.RawUI.ForegroundColor
          $host.UI.RawUI.ForegroundColor = $Color
      
          if ($Screen -eq $true) {Write-Output $Text} #<------ this line
          if ($File -eq $true) {Add-Content -Path $logfile -Value $Text}
      
          $host.UI.RawUI.ForegroundColor = $defaultcolor
      
      }
      
      $Computer | ForEach-Object {
      
          $comp = $_
          $dest = ("\\{0}\C$\Temp\{1}" -f $comp, (Get-Random))
      
          Write-Progress -Activity "Processing" -Status ("Checking status of {0}..." -f $comp)
          if (-Not (Test-Connection -ComputerName $comp -BufferSize 32 -Count 2 -Quiet)) {
      
              Write-Log -Text ("COMPUTER: {0} | STATUS: {1}" -f $comp, "Offline") -Screen $true -File $true -Color Red
              return
      
          }
      
      }

      Does Write-* cause a redraw or something? Can that be stopped?

      Thanks

    • #195083
      Moderator
      Topics: 3
      Replies: 169
      Points: 889
      Helping Hand
      Rank: Major Contributor

      Please wrap your code with pre tags to give it a good format. For now, I have done it for you.

      Coming to your query, where is the $logfile coming from? And for me, the script is executed as expected. Maybe you are noticing the progress bar flickering because the Test-Connection count is less, increase the count to see the progress bar a bit.

      Thank you.

       

Viewing 1 reply thread
  • You must be logged in to reply to this topic.