Skip to content

Document the new -DefaultValue parameter for Read-Host #13401

Open

Description

Prerequisites

  • 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'

The prompt format comes from the Cmdlets working group's decision: PowerShell/PowerShell#14013 (comment)

Articles

  • reference/7.7/Microsoft.PowerShell.Utility/Read-Host.md

Related Source Pull Requests

Related Source Issues

Activity

  1. added
    issue-doc-idea
    needs-triage
    on Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    issue-doc-ideaneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions