【问题标题】:PowerShell cmdlet Test-NetConnection not availablePowerShell cmdlet Test-NetConnection 不可用
【发布时间】:2018-05-14 05:30:24
【问题描述】:

我注意到 cmdlet Test-NetConnection 未安装在 Server 2012 上。由于 Server 2012 附带 PowerShell 版本 3,所以我认为更新到最新版本 5.1 可能会有所帮助。

我进行了更新,但 cmdlet Test-NetConnection 仍然不可用。

只有Test-Connection 存在,但我需要Test-NetConnection 来测试端口。

我现在如何获得Test-NetConnection

PS C:\Windows\system32> $PSVersionTable 名称 值 ---- ----- PS版本 5.1.14409.1005 PSEdition 桌面版 PSCompatibleVersions {1.0、2.0、3.0、4.0...} 构建版本 10.0.14409.1005 CLRVersion 4.0.30319.34209 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 序列化版本 1.1.0.1 PS C:\Windows\system32> Get-Command Test-NetConnection Get-Command :术语“Test-NetConnection”未被识别为 cmdlet 的名称, 函数、脚本文件或可运行的程序。检查名称的拼写,或者如果路径 已包含,请验证路径是否正确,然后重试。 在行:1 字符:1 + Get-Command Test-NetConnection + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (Test-NetConnection:String) [Get-Command], CommandNotFoundException + FullyQualifiedErrorId:CommandNotFoundException,Microsoft.PowerShell.Commands.GetCommandCommand

【问题讨论】:

    标签: powershell windows-server-2012


    【解决方案1】:

    许多 cmdlet 的可用性与 Windows 版本相关,而不是 PowerShell 版本。如果你不能升级你的 Windows 版本,你就不能拥有Test-NetConnection

    您可以使用nmapscanline 等命令行端口扫描器进行端口测试,或者您可以自己连接到端口:

    function Test-Port($server, $port) {
        $client = New-Object Net.Sockets.TcpClient
        try {
            $client.Connect($server, $port)
            $true
        } catch {
            $false
        } finally {
            $client.Dispose()
        }
    }
    

    【讨论】:

    • 太糟糕了。我现在必须坚持下去。我发现这个 cmdlet 非常方便,因为不需要额外安装。我非常感谢你的功能,就像一个魅力!谢谢!
    • 似乎该函数发送一个SYN数据包并且不等待ACK。所以它不如 Test-NetConnection 可靠。
    猜你喜欢
    • 2014-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    • 2021-10-20
    • 1970-01-01
    相关资源
    最近更新 更多