pmdci
pmdci

Reputation: 300

PowerShell: Disable echo in Read-Host

Consider the following example:

Read-Host "Enter a value"

While this works fine, every time the user hits enter after entering a value, the same value is echoed on the next line. This is driving me nuts. There must be a way of remove this stupid echo?

Upvotes: 1

Views: 2463

Answers (3)

awvalenti
awvalenti

Reputation: 2013

On a PowerShell subprocess inside NodeJS, Read-Host didn't work for me. I had to do it this way:

$null = [Console]::ReadLine()

Upvotes: 0

Frank Monroe
Frank Monroe

Reputation: 1621

In PowerShell Core, you need to use -MaskInput as in:

$pwd_string = Read-Host "Enter a Password" -MaskInput

Read-Host reference

Upvotes: 1

Nkosi
Nkosi

Reputation: 247471

Pass the entered value into a variable

$value = Read-Host "Enter a value"

unless I pass the variable back out to host like in the following example

$value = Read-Host "Enter a value"
$value

it won't be echoed.

Upvotes: 3

Related Questions