Created
January 30, 2020 22:51
-
-
Save mavaddat/fe1b4aaea1fde2a835c46b3343b2b4f6 to your computer and use it in GitHub Desktop.
Ask user for confirmation. Function allows you to ask for confirmation. It is written by @hugopeeters
This file contains 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
# Description: Ask a user to answer a question with either yes or no. | |
# Example use: | |
# If (Ask-YesOrNo) | |
# { | |
# # User has confirmed | |
# ... | |
# } | |
# Else | |
# { | |
# # User did not confirm | |
# ... | |
# } | |
Function Ask-YesOrNo | |
{ | |
param([string]$title="Confirm",[string]$message="Are you sure?") | |
$choiceYes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "Answer Yes." | |
$choiceNo = New-Object System.Management.Automation.Host.ChoiceDescription "&No", "Answer No." | |
$options = [System.Management.Automation.Host.ChoiceDescription[]]($choiceYes, $choiceNo) | |
$result = $host.ui.PromptForChoice($title, $message, $options, 1) | |
switch ($result) | |
{ | |
0 | |
{ | |
Return $true | |
} | |
1 | |
{ | |
Return $false | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment