How to Use -confirm in PowerShell

后端 未结 10 1426
遥遥无期
遥遥无期 2020-12-07 20:10

I\'m trying to take user input and before proceeding I would like get a message on screen and than a confirmation, whether user wants to proceed or not. I\'m using the follo

10条回答
  •  情书的邮戳
    2020-12-07 20:40

    This is a simple loop that keeps prompting unless the user selects 'y' or 'n'

    $confirmation = Read-Host "Ready? [y/n]"
    while($confirmation -ne "y")
    {
        if ($confirmation -eq 'n') {exit}
        $confirmation = Read-Host "Ready? [y/n]"
    }
    

提交回复
热议问题