代码之家  ›  专栏  ›  技术社区  ›  Saagar

Linux到Windows-远程执行.exe

  •  1
  • Saagar  · 技术社区  · 6 年前

    我们需要使用参数从Linux计算机远程执行.exe到Windows 10。所以我们在CentOS上安装了powershell。下面是我们使用的命令:

    Invoke-Command -HostName abcdefg -Credential $creds -ScriptBlock { Start-Process -FilePath "C:\sip\GetProcessInstance.exe" -$args[0] } -ArgumentList "http://hostname:8080/jbpm-console/rest/task/listUserTasks?potentialOwner=abc@xyz.com"
    
    Invoke-Command -HostName abcdefg -Credential $creds -ScriptBlock { Start-Process -FilePath "C:\sip\GetProcessInstance.exe" -ArgumentList "http://hostname:8080/jbpm-console/rest/task/listUserTasks?potentialOwner=abc@xyz.com" }
    
    Invoke-Command -HostName abcdefg -Credential $creds -ScriptBlock { Get-ChildItem C:\ }
    

    获取跟踪错误

    调用命令:无法使用指定的命名参数解析参数集。发出的一个或多个参数不能一起使用,或者提供的参数数量不足。
    在第1行字符:1

    enter image description here

    对于windows到windows也是如此。

    1 回复  |  直到 6 年前
        1
  •  2
  •   Robert Dyjas Joey    6 年前

    如错误消息中所述,您正试图使用无效的参数集。一旦你打开 the documentation for Invoke-Command 你可以找到你可以使用的集合。

    看看我链接的文档开头的块。只有两个可能的集合 -HostName 参数:

    Invoke-Command
          -ScriptBlock <scriptblock>
          -HostName <string[]>
          [-Port <int>]
          [-AsJob][-HideComputerName]
          [-UserName <string>]
          [-KeyFilePath <string>]
          [-SSHTransport]
          [-RemoteDebug][-InputObject <psobject>]
          [-ArgumentList <Object[]>]
          [<CommonParameters>]
    
    Invoke-Command
          -FilePath <string>
          -HostName <string[]>
          [-Port <int>]
          [-AsJob]
          [-HideComputerName][-UserName <string>]
          [-KeyFilePath <string>]
          [-SSHTransport]
          [-RemoteDebug]
          [-InputObject <psobject>][-ArgumentList <Object[]>]
          [<CommonParameters>]
    

    如你所见,他们都没有 -Credential 参数可用。你的选择是:

    1. 使用 WinRM 而不是 SSH

    在这种情况下,你必须使用 -ComputerName 参数而不是 -主机名

    1. 使用 -SSHConnection

    从文档中:

    此参数采用哈希表数组,其中每个哈希表包含建立安全shell(ssh)连接所需的一个或多个连接参数(主机名、端口、用户名、keyfilepath)。

    1. 使用上面我粘贴的其中一个集

    由于我不知道你的配置,我不能告诉你哪一个最适合你,所以你必须自己选择。

    推荐文章