$procs = Get-Process -Name java -ErrorAction SilentlyContinue
if ($procs) {
    foreach ($p in $procs) {
        $procId = $p.Id
        $cmd = (Get-CimInstance Win32_Process -Filter "ProcessId=$procId").CommandLine
        Write-Output "PID: $procId CMD: $cmd"
    }
} else {
    Write-Output "No Java processes found"
}
