Q:

How do I monitor Windows Java processes with "Get-wmiObject"

I have some java components that sometimes die and the only way I know is when a user compains they've gotten an error.  
What I've done on our monitoring systems is count the amount of java processes running on the server.  If a component dies, I get alerted that the java threshold is below normal and I log in to find out which one of the java components died.  It works, but I think it could be refined to which component died and be able to start the java process remotely.
So what I was thinking is writing a Powershell script that is executed from the monitoring system.  I think I have most of the 'one liner' but need a little more help getting me to the finish line, as I think this script doesn't need to be elaborate.
What I have so far is:
$theProcess = Get-WmiObject win32_process -Filter "name like '%java%'" | select commandLine

The output of this command gives me all the parameters sent to the JVM, including the name of the component, lets call the component "COMP_Number1", and usually there are 5 java component processes running, so the name of the components are "COMP_Number2", "COMP_Number3", and so on.  
My question is:  Given the output of $theProcess, how do I check all the java processes to validate that all of the components are running? And if not, which one is not running?
Much Appreciated!
TT

A:

You can do something like this:
$components = @("COMP_Number1","COMP_Number2")
$theProcess | %{ 
    $p = $_
    $running = $components | ?{$p.commandline -match $_}
    $notrunning = $components | ?{ $running -notcontains $_ }
}

$notrunning

