Write-Progress with Write-Output

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

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.