You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Document the new -DefaultValue parameter for Read-Host #13401
Existing Issue: Search the existing issues for this repository. If there is an issue that fits your needs do not file a new one. Subscribe, react, or comment on that issue instead.
Descriptive Title: Write the title for this issue as a short synopsis. If possible, provide context. For example, "Document new Get-Foo cmdlet" instead of "New cmdlet."
Summary
I've opened a PR that adds a -DefaultValue parameter to Read-Host (PowerShell/PowerShell#28464). It lets a script suggest an answer: the prompt shows the default, and if the user just presses Enter, Read-Host returns it. The Read-Host page will need the new parameter and an example once it's merged.
Details
How it works, so the docs can match:
-DefaultValue <string>, optional, named only (no position, no pipeline input, no wildcards).
With -Prompt, the prompt reads <prompt> (default: <value>): . Without -Prompt, Read-Host writes (default: <value>): before reading.
Pressing Enter without typing returns the default. Anything typed is returned as is.
It's in the same parameter set as -MaskInput, so it can't be combined with -AsSecureString. With -MaskInput the typing is hidden, but the default still shows in the prompt.
Example:
$color=Read-Host-Prompt 'Favorite color'-DefaultValue 'blue'# Favorite color (default: blue): <Enter># $color is 'blue'
Activity