PowerShell Logo Small


This is the built-in help made by Microsoft for the document 'about_PSConsoleHostReadLine', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-24.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

Search powershellhelp.space


Explains how to create a customize how Windows PowerShell reads input
at the console prompt.

Starting in Windows PowerShell V3, you can write a function named
PSConsoleHostReadLine that overrides the default way that console
input is processed.

The following example launches Notepad and gets input from a text
File that the user creates:
function PSConsoleHostReadLine
    $inputFile = Join-Path $env:TEMP PSConsoleHostReadLine
    Set-Content $inputFile "PS > "
    ## Notepad opens. Enter your command in it, save the file,
    ## and then exit.
    notepad $inputFile | Out-Null
    $userInput = Get-Content $inputFile
    $resultingCommand = $userInput.Replace("PS >", "")
By default, Windows PowerShell reads input from the console in what
is known as “Cooked Mode”—in which the Windows console subsystem
handles all the keypresses, F7 menus, and other input. When you press
Enter or Tab, Windows PowerShell gets the text that you have typed up
to that point. There is no way for it to know that you pressed Ctrl-R,
Ctrl-A, Ctrl-E, or any other keys before pressing Enter or Tab. In
Windows PowerShell version 3, the PSConsoleHostReadLine function solves
this issue. When you define a function named PSConsoleHostReadline in
the Windows PowerShell console host, Windows PowerShell calls that
function instead of the “Cooked Mode” input mechanism.