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

    • Related Articles

    • How to find unused Exchange Online mailboxes

      What are unused Exchange Online mailboxes and how to identify them? Unused Exchange Online mailboxes are user mailboxes which are currently not being used by their users. There are 3 ways in which we can identify if a mailbox is unused or not. They ...
    • Generate an Activity Report for Microsoft 365 Groups and Teams

      Introduction The activity reports available for Microsoft 365 groups and Teams can be beneficial for administrators in an organization. Microsoft 365 teams group activity reports provide insight into group activities, group workloads, group counts, ...
    • 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.   ...
    • Performing bulk operations in Microsoft 365 with PowerShell

      Performing bulk operations in Microsoft 365 with PowerShell, such as bulk adding users or modifying attributes, can be a very useful and efficient way to manage your organization's users and resources. PowerShell is a powerful command-line tool that ...
    • How to monitor Microsoft 365 email and mailbox activity with PowerShell

      Monitoring Microsoft 365 email and mailbox activity with PowerShell can be a crucial part of managing your organization's email security and compliance. With PowerShell, you can quickly and easily automate the process of monitoring email and mailbox ...