Prompt the user to select yes/no in PowerShell

#powershell #ui

Prompt the interactive user to answer โ€˜yesโ€™ or โ€˜noโ€™ in response to a query.

PowerShell

This example sets โ€˜yesโ€™ as the default answer

0 -eq $Host.UI.PromptForChoice('caption', 'prompt text', @('&Yes', '&No'), 0)

Outputs

$true if the user answers โ€˜yesโ€™ $false if the user answers โ€˜noโ€™