0
0
PowerShellscripting~30 mins

Process management (Get/Stop-Process) in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Process Management with Get-Process and Stop-Process
📖 Scenario: You are managing your computer's running programs. Sometimes, a program uses too much memory or is not responding. You want to find these programs and stop them safely.
🎯 Goal: You will write a PowerShell script that lists running processes, sets a memory usage limit, finds processes using more memory than this limit, and stops those processes.
📋 What You'll Learn
Create a variable with a list of running processes using Get-Process
Create a variable called memoryLimitMB with a value of 100
Use a foreach loop to find processes using more than memoryLimitMB megabytes of memory
Stop those processes using Stop-Process
Print the names of stopped processes
💡 Why This Matters
🌍 Real World
System administrators often need to manage processes that use too much memory or cause problems. This script helps automate that task.
💼 Career
Knowing how to list, filter, and stop processes is useful for IT support, system administration, and automation roles.
Progress0 / 4 steps
1
Get the list of running processes
Create a variable called processes and set it to the list of all running processes using Get-Process.
PowerShell
Need a hint?

Use Get-Process to get all running processes and assign it to processes.

2
Set the memory usage limit
Create a variable called memoryLimitMB and set it to 100 to represent 100 megabytes.
PowerShell
Need a hint?

Just assign the number 100 to memoryLimitMB.

3
Find and stop processes using too much memory
Use a foreach loop with variable proc to go through processes. Inside the loop, check if proc.WorkingSet / 1MB is greater than memoryLimitMB. If yes, stop the process using Stop-Process -Id $proc.Id and print the process name with Write-Output.
PowerShell
Need a hint?

Use foreach ($proc in $processes) to loop. Check memory with $proc.WorkingSet / 1MB. Use Stop-Process -Id $proc.Id to stop.

4
Run the script and see stopped processes
Run the script to see the names of processes stopped because they used more than 100 MB memory.
PowerShell
Need a hint?

Run the script. If any process uses more than 100 MB, you will see lines like Stopped process: processname.