Erkennen, die Anzahl der Laufenden Prozesse mit dem gleichen Namen

Irgendwelche Ideen, wie man eine Funktion schreiben, die gibt die Anzahl der Instanzen eines Prozesses ausgeführt wird?

Vielleicht so etwas?

function numInstances([string]$process)
{
    $i = 0
    while(<we can get a new process with name $process>)
    {
        $i++
    }

    return $i
}

Edit: Angefangen zu schreiben eine Funktion... Es funktioniert für eine einzelne Instanz, sondern es geht in eine unendliche Schleife, wenn mehr als eine Instanz ausgeführt wird:

function numInstances([string]$process)
{
$i = 0
$ids = @()
while(((get-process $process) | where {$ids -notcontains $_.ID}) -ne $null)
    {
    $ids += (get-process $process).ID
    $i++
    }

return $i
}
InformationsquelleAutor Jack | 2011-07-08
Schreibe einen Kommentar