【发布时间】:2019-10-02 22:54:10
【问题描述】:
我想创建一个确认框。我想要一个弹出框,显示这似乎是工厂密钥。你想继续吗?如果是,则继续执行脚本的其余部分,如果不是,则退出脚本。
以下是我的脚本:
if (Test-Path $USB2\sources\install3.swm) {
$caption = "*** IT APPEARS THIS IS A FACTORY KEY ***"
$message = "Are you Sure You Want To Proceed:"
[int]$defaultChoice = 1
$yes = New-Object System.Management.Automation.Host.ChoiceDescription "&Yes", "I understand, flash over it."
$no = New-Object System.Management.Automation.Host.ChoiceDescription "&No"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)
$choiceRTN = $host.UI.PromptForChoice($caption, $message, $options, $defaultChoice)
if ( $choiceRTN -ne 1 ) {
"Your Choice was Yes"
} else {
Stop-Process -Id $PID
}
}
见位,$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)。我被卡住的地方是“你的选择是肯定的”,我不需要那个......如果是的话,我只需要它来继续脚本。我该怎么做?
【问题讨论】:
-
您是否使用过许多 Cmdlet 中的
-Confirm标志?无论如何,我会看到stackoverflow.com/questions/24649019/… -
if ($choiceRTN -eq 1) { exit }然后添加脚本的其余部分。
标签: powershell