From f88241b7942e343eeef08ab583212e682df89eb3 Mon Sep 17 00:00:00 2001 From: Adam Bertram Date: Tue, 20 Mar 2018 08:29:18 -0500 Subject: [PATCH] updates --- Random Stuff/Confirm-Choice.ps1 | 34 +++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Random Stuff/Confirm-Choice.ps1 diff --git a/Random Stuff/Confirm-Choice.ps1 b/Random Stuff/Confirm-Choice.ps1 new file mode 100644 index 0000000..5f04c04 --- /dev/null +++ b/Random Stuff/Confirm-Choice.ps1 @@ -0,0 +1,34 @@ +function Confirm-Choice { + [OutputType('boolean')] + [CmdletBinding()] + param + ( + [Parameter()] + [ValidateNotNullOrEmpty()] + [string]$Title, + + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string]$PromptMessage + ) + + $yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes" + $no = New-Object System.Management.Automation.Host.ChoiceDescription "&No" + $options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no) + + if ($PSBoundParameters.ContainsKey('Title')) { + Write-Host -Object $Title -ForegroundColor Cyan + } + + Write-Host -Object $PromptMessage -ForegroundColor Cyan + $result = $host.ui.PromptForChoice($null, $null, $Options, 1) + + switch ($result) { + 0 { + $true + } + 1 { + $false + } + } +} \ No newline at end of file