0
votes

I'm trying to connect a remote server and stop a process on it using this PowerShell command

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

but I got this error message after executing it:

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
Remove the leading backslashes from the computer name.Ansgar Wiechers

1 Answers

0
votes

Here a PowerShell code that worked:

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