【发布时间】:2021-06-08 01:01:06
【问题描述】:
我试过Test-Connection -TargetName www.google.com,也就是what most examples show。我收到错误“找不到与参数匹配的参数”名称'TargetName'。”
我在谷歌上搜索该错误时没有找到很多结果。
我使用的是 Powershell 5.1 版,我通过运行 $PSVersionTable 知道它。
【问题讨论】:
标签: powershell
我试过Test-Connection -TargetName www.google.com,也就是what most examples show。我收到错误“找不到与参数匹配的参数”名称'TargetName'。”
我在谷歌上搜索该错误时没有找到很多结果。
我使用的是 Powershell 5.1 版,我通过运行 $PSVersionTable 知道它。
【问题讨论】:
标签: powershell
我发现参数名称的首选方法是Get-Command -Syntax——在这种情况下,5.1 中的正确名称是ComputerName:
PS ~> Get-Command Test-Connection -Syntax
Test-Connection [-ComputerName] <string[]> [-AsJob] [-DcomAuthentication <AuthenticationLevel>] [-WsmanAuthentication <string>] [-Protocol <string>] [-BufferSize <int>] [-Count <int>] [-Impersonation <ImpersonationLevel>] [-ThrottleLimit <int>] [-TimeToLive <int>] [-Delay <int>] [<CommonParameters>]
Test-Connection [-ComputerName] <string[]> [-Source] <string[]> [-AsJob] [-DcomAuthentication <AuthenticationLevel>] [-WsmanAuthentication <string>] [-Protocol <string>] [-BufferSize <int>] [-Count <int>] [-Credential <pscredential>] [-Impersonation <ImpersonationLevel>] [-ThrottleLimit <int>] [-TimeToLive <int>] [-Delay <int>] [<CommonParameters>]
Test-Connection [-ComputerName] <string[]> [-DcomAuthentication <AuthenticationLevel>] [-WsmanAuthentication <string>] [-Protocol <string>] [-BufferSize <int>] [-Count <int>] [-Impersonation <ImpersonationLevel>] [-TimeToLive <int>] [-Delay <int>] [-Quiet] [<CommonParameters>]
【讨论】:
帮助我找到解决方案的只是输入Test-Connection 并查看它会提示我输入什么参数。它提示我ComputerName。然后我尝试运行Test-Connection -ComputerName www.google.com,它成功了!
【讨论】:
5.1,您会发现所有示例都使用-ComputerName :-)