我不明白为什么这个简单的powershell -OR不起作用。 如果我使用大于 3 的任何内容,if 语句有效,但 OR 不起作用。 如果我使用小于 1 的零,它不会进入 if 块。
if($ActionType -gt 3 -Or $ActionType -lt 1)
{
}
有什么想法吗?
与评论员一致,您似乎正在尝试将string
与int
进行比较。
假设$ActionType.Length != 0 || null
:
Try
{
$Compare = [int]$ActionType
if ($Compare -gt 3 -or $Compare -lt 1) { <# ... #> }
}
Catch
{
Write-Host "Conversion failed! $PSItem"
}
不过,在这种特殊情况下,我想我更喜欢更干净的语法:
if (1,2,3 -notcontains $ActionType) { }