Powershell if -or语句

时间:2018-04-06 15:53:45

标签: powershell

我无法理解为什么这个简单的PowerShell -OR不起作用。如果我使用大于3的if语句,那么OR就不起作用了。如果我使用零,那将小于1,它就不会进入if块。

getCurrentPosition()
    .then(response => {
        // response should equal {lat: xxx, lng: xxx}
    })
    .catch(err => {
        console.log(err)
    });

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

与评论员一致,您似乎正在尝试将stringint进行比较。

假设$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) { }