Show-Input

Shows prompt message box asking user to provide a text string.

Syntax

Show-Input [-Prompt] <String> [-DefaultValue <String>] [-Validation <String>] [-ErrorMessage <String>] [-MaxLength <Int32>]

Detailed Description

Shows prompt message box asking user to provide a text string.

© 2010-2019 Adam Najmanowicz, Michael West. All rights reserved. Sitecore PowerShell Extensions

Parameters

-Prompt <String>

Prompt message to show in the message box shown to a user.

Aliases

Required?

true

Position?

1

Default Value

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-DefaultValue <String>

Default value to be provided for the text box.

Aliases

Required?

false

Position?

named

Default Value

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Validation <String>

Regex for value validation. If user enters a value that does not validate - en error message defined with the "ErrorMessage" parameter will be shown and user will be asked to enter the value again.

Aliases

Required?

false

Position?

named

Default Value

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ErrorMessage <String>

Error message to show when regex validation fails.

Aliases

Required?

false

Position?

named

Default Value

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-MaxLength <Int32>

Maximum length of the string returned. If user enters a longer value - en error message will be shown and user will be asked to enter the value again.

Aliases

Required?

false

Position?

named

Default Value

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

Outputs

The output type is the type of the objects that the cmdlet emits.

  • System.String

Notes

Help Author: Adam Najmanowicz, Michael West

Examples

EXAMPLE 1

Requests that the user provides an email, validates it against a regular expression snd whows an allert if the format is not valid

PS master:\> Show-Input "Please provide your email" -DefaultValue "my@email.com"  -Validation "^[a-zA-Z0-9_-]+(?:\.[a-zA-Z0-9_-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$" -ErrorMessage "Not a proper email!"

EXAMPLE 2

Uses Show-Input command to request user a new name for the content item validating the proper characters are used and assigns the result to $newName variable (nothing gets changed)

PS master:\> $contentItem = get-item master:\content
PS master:\> $newName = Show-Input "Please provide the new name for the '$($contentItem.Name)' Item" -DefaultValue $contentItem.Name  -Validation "^[\w\*\$][\w\s\-\$]*(\(\d{1,}\)){0,1}$" -ErrorMessage "Invalid characters in the name"

#print new name
PS master:\> Write-Host "The new name you've chosen is '$($newName)'"

EXAMPLE 3

Requests that the user provides a string of at most 5 characters

Show-Input "Please provide 5 characters at most" -MaxLength 5

Last updated