0
0
PowerShellscripting~5 mins

Process management (Get/Stop-Process) in PowerShell

Choose your learning style9 modes available
Introduction

Process management helps you see and control programs running on your computer. You can find and stop programs easily.

You want to check if a program is running before starting it again.
You need to stop a program that is frozen or not responding.
You want to see all running programs to understand what your computer is doing.
You want to stop a background task that is using too much memory.
You want to automate closing certain programs at a specific time.
Syntax
PowerShell
Get-Process [-Name <string[]>] [-Id <int[]>]
Stop-Process [-Name <string[]>] [-Id <int[]>] [-Force]

Get-Process shows running programs by name or ID.

Stop-Process stops a program by name or ID. Use -Force to stop it immediately.

Examples
Shows all running processes on your computer.
PowerShell
Get-Process
Shows only the Notepad program if it is running.
PowerShell
Get-Process -Name notepad
Stops the Notepad program safely.
PowerShell
Stop-Process -Name notepad
Forces the process with ID 1234 to stop immediately.
PowerShell
Stop-Process -Id 1234 -Force
Sample Program

This script shows all running Notepad processes, stops them, then tries to show them again to confirm they stopped.

PowerShell
Write-Host "List of running Notepad processes:"
Get-Process -Name notepad

Write-Host "Stopping all Notepad processes..."
Stop-Process -Name notepad

Write-Host "Notepad processes after stopping:"
Get-Process -Name notepad -ErrorAction SilentlyContinue
OutputSuccess
Important Notes

If you try to stop a process that is not running, PowerShell shows an error unless you use -ErrorAction SilentlyContinue.

Use Get-Process to find the exact name or ID of the process before stopping it.

Stopping system processes can cause your computer to crash. Only stop processes you know.

Summary

Get-Process shows running programs by name or ID.

Stop-Process stops programs safely or forcefully.

Use these commands to control programs running on your computer easily.