Techibee.com

PowerShell: Get individual process count

I am a very bad user of my PC. I open many IE, notepad and other application windows sand leave them like that. I only care to close them only when my computer starts behaving crazy :-/

Today I did the same exercise of closing old/unused application windows to give some breathing room for my computer. While doing it I was curios to know what is the count of each process running on my computer so that I can see the top processes and close the ones which are high in number. And immediately, I authored this script.

[cmdletbinding()]            

param(
$ComputerName = $env:computername
)
$Processes = Get-Process -ComputerName $ComputerName
$myprocesses = @()
foreach($process in $processes) {
  $myprocesses = $myprocesses + $process.Name
}
$hash =@{}
$myprocesses | % {$hash[$_] = $hash[$_] + 1 }
$hash.getenumerator() | ? { $_.value -gt 1 } | sort value

All I am doing is reading the process names into a array called $myprocesses and applying the one of my previous powershell inventions which can detect the duplicates in an array and give the count. This one proved to be handy for me many times.

So, after executing the script, I can see that too many notepad.exe processes are running….. Thank you PS. I will close them first. 🙂

Thank you for reading. Let me know if you come across this small tip handy anywhere.

Happy reading…

 

Exit mobile version