Powershell Press Any Key To Continue

When I start Bash on Ubuntu, the Bash terminal displayed: Error: 0x800703fa Press any key to continue. My windows build: Microsoft Windows Version 10.0. The only thing i did before th. The Wait-KeyPress cmdlet pauses the Powershell session until the user presses a key. Message The message to display to the user. By default the message is 'Press any key to continue.' Quiet Do not display a message. Inputs Wait-KeyPress does not accept input objects. Outputs Wait-KeyPress does not output any Powershell objects.

Everyone once in a while I come across a PowerShell script that behaves like an old-fashioned batch file. Not that there’s anything wrong with that, but often these types of scripts put in a pause at the end of script so you can see that it finished. You might have seen a command like this in a PowerShell script.

Sure, it works but is hardly elegant PowerShell. First, I’m not sure you even need it. If you want to draw attention to the fact that your script ended, consider using Write-Host with a foreground (or background color).

But if you truly need the user to acknowledge that the script has finished you can use Read-Host.

I’m piping the command to Out-Null because I don’t care what the user enters, only that they hit a key.

If you prefer a move visual cue, you can always resort to the Wscript.Shell COM object.

The popup will remain until the user clicks OK. Or you can change the second parameter from 0 to another value to have the popup automatically dismiss after the specified number of seconds.

So if you need a refreshing pause, there are plenty of PowerShell options for you to use.

UPDATE:
After someone posted a comment I realized there is yet another way to do this. Add these two lines to the end of your PowerShell script.

This is very similar behavior to Read-Host but with a bit more flexibility.

Press -->

Definition

Obtains the next character or function key pressed by the user.

Overloads

ReadKey()

Obtains the next character or function key pressed by the user. The pressed key is displayed in the console window.

ReadKey(Boolean)

Obtains the next character or function key pressed by the user. The pressed key is optionally displayed in the console window.

Obtains the next character or function key pressed by the user. The pressed key is displayed in the console window.

Returns

ConsoleKeyInfo

An object that describes the ConsoleKey constant and Unicode character, if any, that correspond to the pressed console key. The ConsoleKeyInfo object also describes, in a bitwise combination of ConsoleModifiers values, whether one or more Shift, Alt, or Ctrl modifier keys was pressed simultaneously with the console key.

Exceptions

The In property is redirected from some stream other than the console.

Examples

One of the most common uses of the ReadKey() method is to halt program execution until the user presses a key and the app either terminates or displays an additional window of information. The following example uses the ReadKey() method to wait for the user to press the Enter key before terminating the app.

Note that this overload of the ReadKey method by default echoes any displayable keys that the user presses to the console. To suppress them, call the ReadKey method with an intercept argument of true.

The following example uses the ReadKey() method to display information about which key the user pressed.

Remarks

The ReadKey method waits, that is, blocks on the thread issuing the ReadKey method, until a character or function key is pressed. A character or function key can be pressed in combination with one or more Alt, Ctrl, or Shift modifier keys. However, pressing a modifier key by itself will not cause the ReadKey method to return.

Depending on your application, you might want to use the ReadKey method in conjunction with the KeyAvailable property.

The ReadKey method reads from the keyboard even if the standard input is redirected to a file with the SetIn method.

See also

Applies to

Obtains the next character or function key pressed by the user. The pressed key is optionally displayed in the console window.

Parameters

intercept
Boolean

Determines whether to display the pressed key in the console window. true to not display the pressed key; otherwise, false.

Returns

ConsoleKeyInfo

An object that describes the ConsoleKey constant and Unicode character, if any, that correspond to the pressed console key. The ConsoleKeyInfo object also describes, in a bitwise combination of ConsoleModifiers values, whether one or more Shift, Alt, or Ctrl modifier keys was pressed simultaneously with the console key.

Exceptions

The In property is redirected from some stream other than the console.

Examples

Powershell 5 Press Any Key To Continue

One of the most common uses of the ReadKey method is to halt program execution until the user presses a key and the app either terminates or displays an additional window of information. The following example uses the ReadKey(Boolean) method to wait for the user to press the Enter key before terminating the app. Note that, if the user presses any other key, it is not echoed to the console.

The following example uses the ReadKey(Boolean) method to display information about the key pressed by a user without echoing that key to the console.

Remarks

Powershell

The ReadKey method waits, that is, blocks on the thread issuing the ReadKey method, until a character or function key is pressed. A character or function key can be pressed in combination with one or more Alt, Ctrl, or Shift modifier keys. However, pressing a modifier key by itself will not cause the ReadKey method to return.

If the intercept parameter is true, the pressed key is intercepted and not displayed in the console window; otherwise, the pressed key is displayed.

Depending on your application, you might want to use the ReadKey method in conjunction with the KeyAvailable property.

The ReadKey method reads from the keyboard even if the standard input is redirected to a file with the SetIn method.

See also

Powershell Press Any Key To Continue Ise

Powershell Press Any Key To Continue

Powershell Press Any Key To Continue Enter

Applies to