Code: Select all
# Text to be read by user:
Write-Host "Line of text at the very top"
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host "Line of text in the middle"
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host
Write-Host "Last line of text"
Write-Host "Executing in:"
Write-Host
# Countdown:
$topRow = [System.Console]::CursorTop
3..0 | ForEach-Object {
[System.Console]::SetCursorPosition(0, $topRow)
if ($_ -eq 3) { # Showcase of the first digit / second
Write-Host
Write-Host
Write-Host " Executing deletion in"
Write-Host
Write-Host " ► $_ ◄"
Write-Host " "
Write-Host " seconds"
Write-Host
} else { # Showcase of the remaining digits / seconds
Write-Host
Write-Host
Write-Host " Executing deletion in"
Write-Host
Write-Host " ► $_ ◄"
Write-Host " "
Write-Host " seconds"
Write-Host
}
Start-Sleep -Seconds 1
Write-Host " `b"
}
# Here will be the main script
# Post execution message
Write-Host
Write-Host "Script has been executed"
Read-Host
But the problem with it is that each next shown digit makes the PowerShell window scroll down its content to its bottom - thus I can see only for less than second what is above this active counter. I mean: I can constantly scroll up manually but nevertheless it always goes back to the bottom to show a new digit. I could of course use a silent countdown like this
Code: Select all
$CountdownSeconds = 3
Write-Host "Executing in:"
Write-Host $CountdownSeconds
Write-Host "seconds"
Start-Sleep -Seconds $CountdownSeconds
So is there a way to eat a cake and have it - i.e. to see a dynamic countdown at the bottom of PS window but also at any time to be able to scroll up within it and not have focus thrown down every second?