所以使用-quiet开关的Test-Connection可以返回一个布尔值。 现在我需要以某种方式测试以确定是真还是假,然后执行依赖于该结果的动作。 那可能吗? 我是Powershell的新手,但我假设逻辑如下:
If {Test-Connection -quiet PCNAME} == TRUE then.. Else...有任何想法吗?
So Test-Connection with the -quiet switch can return a boolean. Now I need to somehow test to see whether that is True or False, then carry out an action dependent on that result. Is that possible? I'm fairly new to Powershell but I assume logic as follows:
If {Test-Connection -quiet PCNAME} == TRUE then.. Else...Any ideas?
最满意答案
语法不正确
if (Test-Connection -quiet PCNAME) { # bla bla bla } else { # bla bla bla }此外,powershell没有==运算符,而是使用-eq 。
例如if ($foo -eq 0) { ... }
与之相似:
-ne不等于
-gt大于
-gte大于或等于
-lt小于
-lte小于或等于
the syntax is incorrect
if (Test-Connection -quiet PCNAME) { # bla bla bla } else { # bla bla bla }Also, powershell doesnt have an == operator, instead use -eq.
for example if ($foo -eq 0) { ... }
Similary:
-ne not equals
-gt greater than
-gte greater than or equal to
-lt less than
-lte less than or equal to
更多推荐
发布评论