Any ideas on how to write a function that returns the number of process instances are running?
Perhaps something like this?
function numInstances([string]$process) { $i = 0 while(<we can get a new process with name $process>) { $i++ } return $i }
Edit: started writing a function ... It works for one instance, but it goes into an infinite loop if more than one instance works:
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 }
source share