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

    Limited-period offers on our IAM solutions




      • Related Articles

      • Powershell Script to Find and Replace Text in a File

        To find and replace a particular word throughout a file on multiple computers is as laborious as one can imagine. However, with the help of the following PowerShell script, one can easily find a particular word and replace it with a word of choice.   ...
      • PowerShell for AD user reports

        Real-time insights on user account status and activity can help AD  administrators manage accounts better. Many administrators use Microsoft's PowerShell scripts to generate Active Directory reports  and pull detailed information. Below are some ...
      • PowerShell for AD group reports

        Real-time insights on group membership, type, and scope can help Active Directory (AD) administrators manage group objects better. Many administrators use Microsoft's PowerShell technology to run basic queries and pull detailed information. Below are ...
      • Remove duplicates in a PowerShell array

        Administrators often have to deal with arrays of duplicate values such as when querying for installed software registry keys. Manually identifying the duplicate values and removing them is next to impossible when done at scale. With PowerShell, you ...
      • PowerShell as an AD group management tool

        Group management can be quite a challenge for Active Directory (AD) administrators day in, day out. Many administrators use Microsoft's PowerShell technology to perform basic AD user management tasks. Below are some key PowerShell scripts and ...