Skip to content

Read-SpectreText

Synopsis

Prompts the user with a question and returns the user’s input.


Description

This function uses Spectre Console to prompt the user with a question and returns the user’s input. The function takes two parameters: $Question and $DefaultAnswer. $Question is the question to prompt the user with, and $DefaultAnswer is the default answer if the user does not provide any input.


Examples

This will prompt the user with the question “What’s your name?” and return the user’s input. If the user does not provide any input, the function will return “Prefer not to say”.

Read-SpectreText -Question "What's your name?" -DefaultAnswer "Prefer not to say"

Parameters

Question

The question to prompt the user with.

TypeRequiredPositionPipelineInput
[String]false1false

DefaultAnswer

The default answer if the user does not provide any input.

TypeRequiredPositionPipelineInput
[String]false2false

AllowEmpty

If specified, the user can provide an empty answer.

TypeRequiredPositionPipelineInput
[Switch]falsenamedfalse

Syntax

Read-SpectreText [[-Question] <String>] [[-DefaultAnswer] <String>] [-AllowEmpty] [<CommonParameters>]