Ask-YesOrNo

Prompt the user for ‘Yes’ or ‘No’.

Function Ask-YesOrNo
{
param([string]$title="Confirmation needed",[string]$message="xxxxxxxxxx. 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}
	}
}

Leave a Reply

Scroll to Top