1

I am starting a java process:

$global:TS = Start-Process -FilePath "$pathTS\jdk\bin\java.exe" -ArgumentList "-jar","`"$pathTS\TestServer.jar`"" -WorkingDirectory ` "$pathTS" ` -PassThru -WindowStyle Hidden

works fine so far.

Now I am trying to terminate that process:

 Invoke-CimMethod -Query 'select * from Win32_Process where CommandLine like "Test-Server"' -MethodName "Terminate"

BTW: I cannot use the ID of the process to terminate it since it is changing somehow.

I am new to PS and now stuck. Maybe someone has in idea.

Thank you! Alex

mklement0
  • 382,024
  • 64
  • 607
  • 775
Alex_DE
  • 25
  • 3

1 Answers1

1

Try to add the wildcard character % to the WHERE clause to find all instances where "Test-Server" is found anywhere in the CommandLine :

... WHERE CommandLine like "%Test-Server%"...

ref : https://learn.microsoft.com/en-us/windows/win32/wmisdk/like-operator

RealHowTo
  • 34,977
  • 11
  • 70
  • 85