How to Find and Kill Running Processes with PowerShell

How to Find and Kill Running Processes with PowerShell

Heavy hardware resource utilization on end-user machines will lead to reduced productivity by hindering users from getting their job done. In this article, we'll discuss how administrators can identify and kill memory-hogging processes. The following PowerShell script will return the top 5 memory-intensive processes.
  1. function Get-CPU
  2. {
  3.     $CPUPercent = @{
  4.         Name = 'CPUPercent'
  5.         Expression = {
  6.             $TotalSec = (New-TimeSpan -Start $_.StartTime).TotalSeconds
  7.             [Math]::Round( ($_.CPU * 100 / $TotalSec), 2)
  8.         }
  9.     }
  10.  
  11.     Get-Process |
  12.     Select-Object -Property Name, $CPUPercent, Description |
  13.     Sort-Object -Property CPUPercent -Descending |
  14.     Select-Object -First 5
  15. }

 

Alternatively, you can run the following PowerShell script to identify the processes consuming more than 25MB RAM and kill them. 


  1. PS C:\> Get-Process | Where-Object { $_.WorkingSet -gt 25000*1024 } | Sort-Object -Property WorkingSet -Descending | Select-Object -First 5
  2.  
  3. Stop-Process -Name Process_Name -Confirm -PassThru