'PowerShell get or stop a particular Java process

I am using PowerShell script to start multiple Java application.

$app = Start-Process -FilePath java -ArgumentList "-jar $path_to_jar" -PassThru

it's working as expected.

But I also have to search a particular Java process and stope/close it.
I cant use process id ($app.ID) as stop script will be a different script.

Can I have some custom name/identifier to these Java process to get a particular process ? like if I can fetch a java process by JAR name etc.

Not sure but in Linux environment I have seen use of -DAPP_INSTANCE_NAME flag , that might be a custom flag to identify a process.

Any help is apricated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source