According to Microsoft's documentation, read-host
lets the user type some input, and then press enter to continue. Not exactly the correct behavior if you want to have "Press any key to continue". (Wait... where's the Any key?!)
Is there a way to accomplish this? Something like read-char
?
I've tried searching for "single character input" and "powershell input" to see if I could find a list of all ways to get input without much luck. And several Stack Overflow questions that looked hopeful use read-host
which doesn't actually work for "press any key..." functionality.
Use cmd /c 'pause' Command to Enable the press any key to continue in the PowerShell. The cmd /c pause command displays the Press any key to continue . . . and pauses the execution until a key is pressed.
Here is what I use.
Write-Host -NoNewLine 'Press any key to continue...'; $null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With