gpt4 book ai didi

PowerShell cmdlet Test-NetConnection 不可用

转载 作者:行者123 更新时间:2023-12-01 00:22:23 52 4
gpt4 key购买 nike

我注意到 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

最佳答案

许多 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()
}
}

关于PowerShell cmdlet Test-NetConnection 不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47570866/

52 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com