Note that there are some explanatory texts on larger screens.

plurals
  1. POPowerShell Script Starts Adding Blank Lines After 100+ Lines of Output?
    primarykey
    data
    text
    <p>I seem to have encountered a weird bug, or I've missed something in my script.</p> <p>In my scripts, I'm showing progress with a faux progress bar function. It works by updating the same line of the console repeatedly, mimicking a progress bar. See the function below:</p> <pre><code># Update-Progress-Bar : v1.0 : 2013-07-29 # Displays a percentage bar. Meant to be used repeatedly to update the same console line (giving the appearance of incrementing progress). # - $Percentage : Determines how much progress is shown on the bar. # - $Message : The message that accompanies the progress bar. function Update-Progress-Bar ($Percentage, $Message){ # Save the current cursor position so we can come back later. $CursorPosition = $Host.UI.RawUI.CursorPosition # Convert the percentage into a proper progress bar. $ProgressBarMax = "20" $ProgressBarCount = [Math]::Floor([Decimal]($Percentage / 5)) $ProgressBar = ("#" * $ProgressBarCount) + (" " * ($ProgressBarMax - $ProgressBarCount)) # Change the format of the percentage depending on length. switch ($Percentage.Length){ 1 {$Percentage = " " + $Percentage + "%"} 2 {$Percentage = " " + $Percentage + "%"} default {$Percentage = $Percentage + "%"} } # Trim or pad the message as necessary. $MessageMaxLength = "50" if ($Message.Length -gt $MessageMaxLength){ $Message = $Message.Remove($MessageMaxLength) } else { $Message = $Message + (" " * ($MessageMaxLength - $Message.Length)) } # Display our progress bar, percentage, and message. Write-Host -nonewline -ForeGroundColor Blue "[$ProgressBar] $Percentage" Write-Host " | $Message" # Revert back to the original cursor position. $Host.UI.RawUI.CursorPosition = $CursorPosition } </code></pre> <p>For whatever reason, after working for about 100+ records (I'm using this as part of a script where I'm regularly performing actions against 1000s of machines), it starts performing double line breaks, which ruins the functionality of the progress bar. So I end up with this...</p> <pre><code>[ 126 / 2275 ] ComputerName1 [ ] 0% | Verifying network connectivity... [## ] 10% | Verifying file system access... [#### ] 20% | Determining installed operating system... [###### ] 30% | Executing action... [####################] 100% | Action Completed [ 127 / 2275 ] ComputerName2 [ ] 0% | Verifying network connectivity... [## ] 10% | Verifying file system access... [#### ] 20% | Determining installed operating system... [###### ] 30% | Executing action... [####################] 100% | Action Completed </code></pre> <p>When I should have....</p> <pre><code>[ 126 / 2275 ] ComputerName1 [####################] 100% | Action Completed [ 127 / 2275 ] ComputerName2 [####################] 100% | Action Completed </code></pre> <p>Any thoughts on this issue and a possible workaround?</p> <p><strong>EDIT #1:</strong> Is it possible that this is happening when I hit the buffer height limit of the console (as in, it starts discarding the old lines of output)?</p> <p><strong>EDIT #2:</strong> I have confirmed that this issue goes away if I increase the buffer width and height of my console window. I'm still not sure how to workaround this bug though. Thoughts?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload