Windows Powershell IF-ELSEIF-ELSE 语句

Cady ·
更新时间:2024-09-21
· 739 次阅读

Where-Object 进行条件判断很方便,如果在判断后执行很多代码可以使用IF-ELSEIF-ELSE语句。语句模板:

代码如下:
If(条件满足){
如果条件满足就执行代码
}
Else
{
如果条件不满足
}

条件判断必须放在圆括号中,执行的代码必须紧跟在后面的花括号中。

代码如下:
PS C:Powershell> $n=8
PS C:Powershell> if($n -gt 15) {"$n  大于 15 " }
PS C:Powershell> if($n -gt 5) {"$n  大于 5 " }
8  大于 5
PS C:Powershell> if($n -lt 0 ){"-1" } elseif($n -eq 0){"0"} else {"1"}
1

您可能感兴趣的文章:Windows Powershell Switch 语句Windows Powershell ForEach-Object 循环Windows Powershell Foreach 循环Windows Powershell Do While 循环Windows Powershell For 循环Windows Powershell Switch 循环



IF ELSEIF windows PowerShell

需要 登录 后方可回复, 如果你还没有账号请 注册新账号