小编Rj *_*Kay的帖子

我如何要求确认?

我想创建一个确认框。我想要一个弹出框,显示这似乎是工厂密钥。你想继续吗?如果是,则继续执行脚本的其余部分;如果不是,则退出脚本。

以下是我的脚本:

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
    }
}
Run Code Online (Sandbox Code Playgroud)

请参阅一点,$options = [System.Management.Automation.Host.ChoiceDescription[]]($yes, $no)。我陷入困境的是“你的选择是”,我不需要它......我只需要它继续执行脚本(如果是)。我怎么做?

powershell

4
推荐指数
1
解决办法
9430
查看次数

标签 统计

powershell ×1