【问题标题】:Not taking the Else-if input powershell with Switch statement不使用带有 Switch 语句的 Else-if 输入 powershell
【发布时间】:2019-08-26 21:24:09
【问题描述】:

我需要有关 PowerShell 代码的帮助。我必须使用 PowerShell 更新几个程序,但在运行脚本时出现错误。

代码的输入为 1 和 0 用于 Switch 条件,其他输入为 foo、boo、Oracle 待更新,根据条件软件将更新。

$param = Read-Host -Prompt "Enter the input 1 or 0"
[bool]$upg = $true
$sftp = Read-Host "Please Enter the softwre to update"
switch ($param)
{
    0{
        Write-Output "Today is monday"
    }
    1
    {
        $prm_prd = Read-Host -Prompt "Are you going for operation upgrade"
        if ($prm_prd -eq $upg)
        {
            Write-Output "System upgrade"

            if ($sftp -eq 'foo')
            {
                Write-Output "foo upgrade"
            }
            elseif ( $sftp -eq 'boo')
            {
                Write-output "boo upgrade"
            }
            elseif ( $sftp -eq 'Oracle')
            {
                Write-output "oracle upgrade"
            }
        }
    }
}

【问题讨论】:

    标签: if-statement switch-statement powershell-5.0


    【解决方案1】:

    你之前没有发布过这种形式吗? Elseif 不是 else-if。

    【讨论】:

    • 嗨@js2010我仍然没有得到解决方案,dows switch 语句如何为 else-if 语句工作,这有点奇怪,为什么它没有进入 else-if 条件
    • elseif。没有破折号-
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多