测试连接返回值(Test

编程入门 行业动态 更新时间:2024-10-24 08:30:28
测试连接返回值(Test-Connection Return Value)

所以使用-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

更多推荐

本文发布于:2023-08-07 05:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1459996.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:返回值   测试   Test

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!