Created
March 8, 2022 19:15
-
-
Save Kqpa/ca72bfe7eb35eab064e4bf5e7fbe52a2 to your computer and use it in GitHub Desktop.
Yes/no function in PowerShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Read-FromUserChoice { | |
.SYNOPSIS | |
param ( | |
[Parameter(Mandatory)]$Message, | |
$Caption, | |
[string[]]$Options = @('&Yes','&No'), | |
[string]$DefaultOption = '&Yes' | |
) | |
$option = $Options.IndexOf($DefaultOption) | |
if ($option -eq '-1') { | |
throw 'The default option specified is not in the list of supplied options' | |
} | |
$Choice = $host.UI.PromptForChoice($Message, $Caption, $Options, $option) | |
return $options[$Choice] -replace '&','' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment