【问题标题】:How to resolve Test-Connection error: "A parameter cannot be found that matches parameter" name 'TargetName'."如何解决测试连接错误:“找不到与参数匹配的参数”名称“TargetName”。”
【发布时间】:2021-06-08 01:01:06
【问题描述】:

我试过Test-Connection -TargetName www.google.com,也就是what most examples show。我收到错误“找不到与参数匹配的参数”名称'TargetName'。”

我在谷歌上搜索该错误时没有找到很多结果。

我使用的是 Powershell 5.1 版,我通过运行 $PSVersionTable 知道它。

【问题讨论】:

    标签: powershell


    【解决方案1】:

    我发现参数名称的首选方法是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>]
    

    【讨论】:

      【解决方案2】:

      帮助我找到解决方案的只是输入Test-Connection 并查看它会提示我输入什么参数。它提示我ComputerName。然后我尝试运行Test-Connection -ComputerName www.google.com,它成功了!

      【讨论】:

      • 文档页面的左上角有一个下拉菜单,您可以在其中选择所需的版本 - 如果您选择5.1,您会发现所有示例都使用-ComputerName :-)
      猜你喜欢
      • 2019-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      相关资源
      最近更新 更多