【问题标题】:Test-Connection mystery测试连接之谜
【发布时间】:2014-12-01 11:38:24
【问题描述】:

我们一直在使用 powershell 脚本来 ping 我们的一些服务器。该脚本直到最近都运行良好,即使机器正常,Test-Connection $machineName -quiet 也会返回 $false! (ping $machineName 工作正常,即使脚本外的 Test-Connection $machineName -quiet 工作正常)。我想到的第一件事是检查用户权限。我可以做些什么来进行更多测试吗?

【问题讨论】:

  • 发布您的代码,有人可能会提供帮助
  • 也许删除-Quiet 可能有助于查明原因。
  • 感谢您的回复。代码很简单 if ((test-connection $hostname -count 1 -quiet) -eq $true) { ...do stuff } else { ..do other stuff} 我仍然认为它与用户有关!但不能完全弄清楚这是如何/为什么发生的。我还没有复制这个问题!
  • 感谢您的回复。指定源机器帮助我确定了问题所在。测试连接-source $machine1 -computername $machine2。这将从 $machine1 而不是 localhost 运行测试连接。
  • 您确定 $hostname 或 $machinename 设置正确(是哪个)?

标签: powershell wmi ping remote-server


【解决方案1】:

尝试将测试连接转换为布尔值。

if ( [bool](test-connection $hostname -count 1 -quiet) -eq $true) { ...do stuff } else { ..do other stuff} 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-12
    • 2014-08-18
    • 2015-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多