连接远程服务器并执行脚本

时间:2016-08-25 10:02:17

标签: powershell remote-server

我尝试使用此PowerShell命令连接远程服务器并在其上停止进程

Invoke-Command -ComputerName \\srvwebui3 -ScriptBlock { 
    Get-Process | Where-Object {
        $_.Path -like "\\abd\net$\abd\versions\Bin\HttpServer.exe"
    } | Stop-Process 
}

但执行后我收到此错误消息:

Invoke-Command : One or more computer names is not valid. If you are trying to
pass a Uri, use the -ConnectionUri parameter or pass Uri objects instead of
strings.
At C:\powerShell\stop-process.ps1:4 char:15
+ Invoke-Command <<<<  -ComputerName \\srvwebui3 -ScriptBlock { Get-Process | Where-Object {$_.Path -like "\\gaia\netlims$\Autolims\MainRls\Bin\HttpServer.exe"} | Stop-Process }
    + CategoryInfo          : InvalidArgument: (System.String[]:String[]) [Invoke-Command], ArgumentException
    + FullyQualifiedErrorId : PSSessionInvalidComputerName,Microsoft.PowerShell.Commands.InvokeCommandCommand

1 个答案:

答案 0 :(得分:0)

这是一个有效的PowerShell代码:

Invoke-Command -ComputerName <computerName> -ScriptBlock {
   Get-Process | Where-Object {
            $_.Path -like \\bbb\abab$\bs\MainRls\Bin\HttpServer.exe"
    } |
    Stop-Process -Force
}