Let’s have a break
Have a break… No, no panda bears here!
Sometimes, we want the user to aknowledge an information before the script continues. We don’t need him to choose something (like we saw yesterday with the dynamic menu) but we want him to read something and decide when the script will continue.
The famous “Press any key to continue”.
So, here we are!
function Pause ($Message="Press any key to continue...") { Write-Host -NoNewLine $Message $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") Write-Host "" }
Wanna test it?
function Pause ($Message="Press any key to continue...") { Write-Host -NoNewLine $Message $null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") Write-Host "" } For ($i=1; $i -le 100; $i++) {Write-Host "o" -NoNewline; Start-Sleep -Milliseconds 50} Write-Host "`nI can't stand it any longer... Have a break and when you'll be ready we'll continue..." Pause For ($i=1; $i -le 100; $i++) {Write-Host "o" -NoNewline; Start-Sleep -Milliseconds 50} Write-Host "`n"