小编Tec*_*hFA的帖子

PowerShell 切换在退出时再次执行

我正在尝试编写一个具有多个开关的 PowerShell 菜单,但无法弄清楚为什么先前运行的命令将在退出时再次执行。任何帮助将不胜感激。到目前为止我的代码如下:

function Show-Menu {
    param (
        [string]$Title = 'Menu'
    )
    Clear-Host
    Write-Host "`n============= $Title =============`n"
    Write-Host "Press 'A' to run all commands"
    Write-Host "Press '1' to run foo"
    Write-Host "Press '2' to run bar"
    Write-Host "Press 'Q' to quit"
}

do {
    Show-Menu
    $Selection = Read-Host "`nPlease make a selection"

    switch ($Selection) {
        'A' {
            $Actions = @('foo', 'bar')
        }
        '1' {
            $Actions = "foo"
        }
        '2' {
            $Actions = "bar"
        }
    }
    
    switch ( $Actions ) { …
Run Code Online (Sandbox Code Playgroud)

powershell switch-statement

0
推荐指数
1
解决办法
662
查看次数

标签 统计

powershell ×1

switch-statement ×1