PSInquirer

A PowerShell port of Inquirer.js — add interactive CLI prompts (text input, confirmations, lists, checkboxes) to your scripts.

2 Stars
⬇️ 12 Downloads
🏷️ v0.2.0 Version
📜 MIT License
Install: Install-Module -Name PSInquirer
⬇️ PowerShell Gallery View on GitHub

Documentation

Overview

PSInquirer is a PowerShell port of Inquirer.js — the popular Node.js library for interactive command-line prompts. It lets you build rich, user-friendly CLI wizards and scripts that gather input through a variety of question types: free-text input, yes/no confirmations, single-choice lists, multi-choice checkboxes, and more.

PSInquirer is ideal for interactive setup scripts, deployment wizards, configuration generators, and any scenario where you need structured input from a user at the terminal.


Installation

Install from the PowerShell Gallery:

# Install for current user
Install-Module -Name PSInquirer -Scope CurrentUser

# Import
Import-Module PSInquirer

Quick Start

Import-Module PSInquirer

$answers = Invoke-PSInquirer @(
    New-PSIQuestion -Type Input    -Name "name"    -Message "What is your name?"
    New-PSIQuestion -Type Confirm  -Name "proceed" -Message "Continue with deployment?" -Default $true
    New-PSIQuestion -Type List     -Name "env"     -Message "Target environment?" -Choices @("dev", "staging", "production")
)

Write-Host "Hello, $($answers.name)! Deploying to $($answers.env)."

Question Types

Input — free text

New-PSIQuestion -Type Input -Name "appName" -Message "Application name:"

Confirm — yes/no

New-PSIQuestion -Type Confirm -Name "overwrite" -Message "Overwrite existing files?" -Default $false

List — single choice from a list

New-PSIQuestion -Type List -Name "region" -Message "Deploy to which region?" `
    -Choices @("us-east-1", "eu-west-1", "ap-southeast-1")

Checkbox — multiple selections

New-PSIQuestion -Type Checkbox -Name "features" -Message "Enable features:" `
    -Choices @("Logging", "Metrics", "Tracing", "Alerting")

Password — masked input

New-PSIQuestion -Type Password -Name "apiKey" -Message "Enter your API key:"

Commands

New-PSIQuestion

Creates a question definition to pass to Invoke-PSInquirer.

ParameterTypeDefaultDescription
-Typestring(required)Question type: Input, Confirm, List, Checkbox, Password
-Namestring(required)Key used to store the answer in the result object
-Messagestring(required)Prompt text displayed to the user
-Defaultobject$nullDefault value used when the user presses Enter
-Choicesstring[]@()Options for List and Checkbox types
-Validatescriptblock$nullValidation function; return $true to accept, an error string to reject
-Whenscriptblock$nullCondition function; question is only shown when this returns $true

Invoke-PSInquirer

Runs a list of questions and returns a single hashtable of answers.

ParameterTypeDescription
-Questionsobject[]Array of question objects created by New-PSIQuestion

Validation

Use the -Validate parameter to enforce input rules:

New-PSIQuestion -Type Input -Name "port" -Message "Port number (1-65535):" -Validate {
    param($value)
    $n = [int]$value
    if ($n -ge 1 -and $n -le 65535) { return $true }
    return "Please enter a valid port number between 1 and 65535."
}

Conditional Questions

Use -When to show a question only when a previous answer satisfies a condition:

$answers = Invoke-PSInquirer @(
    New-PSIQuestion -Type Confirm -Name "useTLS" -Message "Enable TLS?"
    New-PSIQuestion -Type Input   -Name "certPath" -Message "Path to certificate:" -When {
        param($answers) $answers.useTLS -eq $true
    }
)

Examples

Interactive deployment wizard

Import-Module PSInquirer

$answers = Invoke-PSInquirer @(
    New-PSIQuestion -Type Input    -Name "appName" -Message "Application name:"
    New-PSIQuestion -Type List     -Name "env"     -Message "Target environment?" `
                    -Choices @("dev", "staging", "production") -Default "dev"
    New-PSIQuestion -Type Checkbox -Name "steps"   -Message "Deployment steps to run:" `
                    -Choices @("Build", "Test", "Migrate DB", "Deploy", "Smoke Test")
    New-PSIQuestion -Type Confirm  -Name "confirm"  -Message "Proceed with deployment?" -Default $false
)

if (-not $answers.confirm) {
    Write-Host "Deployment cancelled."
    exit 0
}

Write-Host "Deploying $($answers.appName) to $($answers.env)..."
foreach ($step in $answers.steps) {
    Write-Host "  → $step"
}

Collecting credentials interactively

Import-Module PSInquirer

$creds = Invoke-PSInquirer @(
    New-PSIQuestion -Type Input    -Name "username" -Message "Username:"
    New-PSIQuestion -Type Password -Name "password" -Message "Password:"
)

$securePass = ConvertTo-SecureString $creds.password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($creds.username, $securePass)
Connect-MyService -Credential $credential

Dynamic questions based on previous answers

Import-Module PSInquirer

$answers = Invoke-PSInquirer @(
    New-PSIQuestion -Type List    -Name "dbType"   -Message "Database type?" `
                    -Choices @("SQL Server", "PostgreSQL", "MySQL", "SQLite")
    New-PSIQuestion -Type Input   -Name "host"     -Message "Database host:" `
                    -When { param($a) $a.dbType -ne "SQLite" }
    New-PSIQuestion -Type Input   -Name "dbFile"   -Message "SQLite file path:" `
                    -When { param($a) $a.dbType -eq "SQLite" }
    New-PSIQuestion -Type Confirm -Name "useSSL"   -Message "Use SSL/TLS?" `
                    -When { param($a) $a.dbType -ne "SQLite" }
)

Write-Host "Configuring $($answers.dbType) connection..."

Contributing

Contributions are welcome! See the GitHub repository for details.


License

PSInquirer is released under the MIT License.

Related Blog Posts