【问题标题】:Greater-than PowerShell operator giving inaccurate results大于 PowerShell 运算符给出不准确的结果
【发布时间】:2016-08-26 20:05:33
【问题描述】:

由于某种原因,当我调试时 - $debug 等于 1,但当调试器命中 if(numUsers -gt 2) 时,它进入 if 块...

function numUsers()
    {@(query user /server:$server).Count - 1
    }

$debug = numUsers

if(numUsers -gt 2)
    {#true
    }
else
    {#Nothing
    }

我是否正确使用了 -gt 运算符?我是否遗漏了一些非常明显的东西?

欣赏任何见解

【问题讨论】:

    标签: powershell if-statement operators


    【解决方案1】:

    -gt 2 被视为写入 numUsers 调用的参数。

    您可以通过查看 $args 函数中的 $args 的值来了解这一点。

    您需要告诉 powershell 您想单独调用 numUsers 以使其正常工作。

    if ((numUsers) -gt 2) {
        "gt 2"
    } else {
        "lt 2"
    }
    

    【讨论】:

    • 你不需要 $,只需要括号,顺便说一句。
    猜你喜欢
    • 1970-01-01
    • 2017-11-18
    • 2015-02-13
    • 2017-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-20
    相关资源
    最近更新 更多