我看到几个断言可移植性的响应,我的测试证实了他们的断言:
从文件或通过 PSSession 将所有必需的模块导入到具有所需模块的主机。您运行的 PowerShell 控制台(x86 或 x64)的体系结构将决定您导入的模块体系结构。
对于那些:
- 仍然无法完成这项工作并且
- 确实需要可靠的 TCP 测试,但可能不需要 Test-NetConnection 和
- 即使在 PowerShell v2.0 上也需要全部工作
你不妨试试这个。
# Create a TCP Client using .Net & attempt connection to target
$TCPClient = New-Object .net.sockets.tcpclient("[IP address or hostname]",[port])
# At the above point you may see familiar-looking Windows error messages in
# red text. (You may want to use "try/catch" if you intend to loop).
# Otherwise, check your new object's status to see if it worked
$TCPClient.Connected
# The response is either "True" or False"
# Now to avoid leaving idle connections, run:
$TCPClient.Close()
当然,应该可以创建一个循环来测试多个连接,并通过选择 $TCPClient 的属性来输出结果。我的初始测试表明您希望选择这些属性
你测试的地址
$TCPClient.Client.RemoteEndPoint.Address.IPAddressToString
您测试的端口
$TCPClient.Client.RemoteEndPoint.Port
结果
$TCPClient.Connected
HIH