Skip to content

Add -DefaultValue parameter to Read-Host - #28464

Open
Zaid Ali Syed (zaidwhy) wants to merge 1 commit into
PowerShell:masterfrom
zaidwhy:read-host-default-value
Open

Zaid Ali Syed (zaidwhy) wants to merge 1 commit into
PowerShell:masterfrom
zaidwhy:read-host-default-value

Conversation

@zaidwhy

@zaidwhy Zaid Ali Syed (zaidwhy) commented Nov 20, 2026 •

Copy link
Copy Markdown

PR Summary

Add a -DefaultValue parameter to Read-Host so pressing Enter without typing anything returns the provided default value. Fixes #14013.

PR Context

The Cmdlets working group agreed on this behavior on 2024-09-04. [SteveL-MSFT's comment](#14013 (comment)) discusses the agreed design.

With -Prompt, the prompt displays like myprompt (default: blue):. Without -Prompt, it displays (default: blue):. If the user presses Enter without entering anything, the default is returned. If they enter something, their input takes precedence.

-MaskInput is currently allowed with -DefaultValue. Since the default comes from the script author, it is shown in plain text. If reviewers would prefer these parameters to be incompatible, I'm happy to change that.

Testing

  • Added 5 tests covering prompt display, empty input, typed input, usage without -Prompt, and incompatibility with -AsSecureString.
  • Ran both Read-Host test files on Windows 11: 12 passed, 0 failed.

PR Checklist

  • PR has a meaningful title
  • Summarized changes
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge.
  • Breaking changes
    • None
  • User-facing changes
  • Testing - New and feature
    • Make sure you've added a new test if existing tests do not effectively test the code changed

@zaidwhy
Zaid Ali Syed (zaidwhy) requested a review from a team as a code owner November 20, 2026 04:03
Copilot AI balanced review requested due to automatic review settings November 20, 2026 04:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@zaidwhy

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a parameter to Read-Host to allow prefilling the edit buffer

2 participants