Scenario: Let's assume I have a script that spawns a few processes. There may be times when the script has to be aborted. Most times this is fine. However, sometimes one or two of the spawned processes remain running, and are orphaned, because the script has been killed.
Is there any way to find the processes based on their environment (specific environment strings and values set when the script ran/spawned them), and kill them?
OS: Windows 7
Powershell would be a good approach to tackling this problem. You can search the currently running processes and filter them by a number of fields. By storing the processes you want to kill in a variable you can kill them all in one swoop
Here is a TechNet Entry explaining about how to get processes in powershell: https://technet.microsoft.com/en-us/library/ee176855.aspx
As seen in the image you can pipe in a where statement to filter the information that you need.