PowerShell Stop-Process: Kill a Process by Name or ID

PowerShell Stop-Process: Kill a Process by Name or ID

PowerShell Tips Editor 3 min read
PowerShell Stop-Process: Kill a Process by Name or ID

A hung application is blocking your deployment pipeline. A runaway process is consuming all the CPU. An installer froze and needs to be killed before you retry. These are the moments where you need to PowerShell kill process quickly and cleanly. Stop-Process terminates processes by name or ID, handles multiple instances, and supports -Force for stubborn processes. This guide covers every pattern you’ll need.

Quick Answer / TL;DR

# Kill all instances of a process by name
Stop-Process -Name 'notepad' -Force

# Kill a specific process by PID
Stop-Process -Id 4892 -Force

Kill by Process Name

Terminate a process by its name (without .exe):

# Kill one process by name
Stop-Process -Name 'notepad'

# Kill all running instances of chrome
Stop-Process -Name 'chrome'

# Check if process is running before killing
if (Get-Process -Name 'notepad' -ErrorAction SilentlyContinue) {
    Stop-Process -Name 'notepad'
    Write-Output 'Notepad stopped'
} else {
    Write-Output 'Notepad was not running'
}
Notepad stopped

When you kill by name, all processes with that name are terminated. If a machine is running four Chrome instances, Stop-Process -Name 'chrome' kills all four. Use -Id to target a specific instance.

Kill by Process ID

Process IDs (PIDs) uniquely identify a single process instance:

# Get the PID first
$proc = Get-Process -Name 'notepad' | Select-Object -First 1
$proc.Id

# Kill by PID
Stop-Process -Id 12345

# Kill the PID you just found
Stop-Process -Id $proc.Id

# Combined: find and kill a specific instance
Get-Process -Name 'notepad' |
    Where-Object { $_.MainWindowTitle -like '*untitled*' } |
    Stop-Process
12345

Force Kill with -Force

-Force kills the process even if it’s not responding and skips confirmation prompts:

# Force kill a hung process
Stop-Process -Name 'chrome' -Force

# Force kill by PID
Stop-Process -Id 4892 -Force

# Force kill without confirmation
Stop-Process -Name 'explorer' -Force

# Restart Explorer after killing it
Stop-Process -Name 'explorer' -Force
Start-Sleep -Seconds 2
Start-Process explorer

Kill All Instances of a Process

To kill all running instances of a process name:

# Kill all Chrome instances
Stop-Process -Name 'chrome' -Force

# Kill all instances of multiple processes
@('chrome', 'msedge', 'firefox') | ForEach-Object {
    $count = (Get-Process -Name $_ -ErrorAction SilentlyContinue).Count
    if ($count -gt 0) {
        Stop-Process -Name $_ -Force
        Write-Output "Stopped $count instance(s) of $_"
    }
}

# Kill processes by part of name using pipeline
Get-Process | Where-Object { $_.Name -like '*sql*' } |
    Stop-Process -Force
Stopped 4 instance(s) of chrome
Stopped 1 instance(s) of msedge

Confirm Before Killing with -Confirm

# Prompt before each kill
Stop-Process -Name 'chrome' -Confirm

# Preview what would be killed with -WhatIf
Stop-Process -Name 'chrome' -WhatIf
What if: Performing the operation "Stop-Process" on target "chrome (4892)".
What if: Performing the operation "Stop-Process" on target "chrome (5123)".
What if: Performing the operation "Stop-Process" on target "chrome (6341)".

Error Handling When Process Not Found

Stopping a process that doesn’t exist throws an error by default. Handle it cleanly:

# Suppress the error if process doesn't exist
Stop-Process -Name 'notepad' -ErrorAction SilentlyContinue

# Handle the error explicitly
try {
    Stop-Process -Name 'notepad' -ErrorAction Stop
    Write-Output 'Process stopped'
} catch [Microsoft.PowerShell.Commands.ProcessCommandException] {
    Write-Output 'Process not found — nothing to stop'
} catch {
    Write-Error "Unexpected error: $($_.Exception.Message)"
}

# Safe kill function
function Stop-ProcessSafe {
    param([string] $Name)
    $procs = Get-Process -Name $Name -ErrorAction SilentlyContinue
    if ($procs) {
        $procs | Stop-Process -Force
        Write-Output "Stopped $($procs.Count) instance(s) of $Name"
    } else {
        Write-Verbose "$Name is not running"
    }
}
Process stopped

Common Errors and Fixes

  • Cannot stop process owned by another user without admin: Processes owned by another user or by SYSTEM require an elevated session. Run PowerShell as Administrator before using Stop-Process on system processes.
  • Process name without .exe — powershell not powershell.exe: Stop-Process -Name 'powershell.exe' returns “No process found” because PowerShell strips the extension. Use -Name 'powershell' (without .exe). You can verify the correct name with Get-Process | Where-Object { $_.Name -like '*sql*' }.

Related Cmdlets / See Also

Wrapping Up

Stop-Process is the controlled way to terminate processes from PowerShell. Use -Name for all instances of a process, -Id for specific instances, -Force for unresponsive processes, and -WhatIf to preview before bulk kills. Guard with -ErrorAction SilentlyContinue or try/catch when the process might not be running. Your next step: add a process check and kill step to your deployment or cleanup scripts to handle residual processes from previous runs.

Send-Item -To