Bird
Raised Fist0
PowerShellscripting~20 mins

Process management (Get/Stop-Process) in PowerShell - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Process Management Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell command?
Consider the following command run on a system with multiple running processes named 'notepad':

Get-Process -Name notepad | Select-Object -First 1 | Format-Table -Property Id, ProcessName -HideTableHeaders

What will this command output?
PowerShell
Get-Process -Name notepad | Select-Object -First 1 | Format-Table -Property Id, ProcessName -HideTableHeaders
ADisplays all 'notepad' processes with Id and ProcessName including headers
BDisplays the Id and ProcessName of the first 'notepad' process found, without table headers
CThrows an error because Format-Table cannot be used with Select-Object
DDisplays only the ProcessName of all 'notepad' processes
Attempts:
2 left
💡 Hint
Think about how Select-Object and Format-Table work together and what -HideTableHeaders does.
📝 Syntax
intermediate
1:30remaining
Which command correctly stops all running 'calc' processes?
You want to stop all processes named 'calc' using PowerShell. Which of the following commands will do this correctly?
AStop-Process -ProcessName calc
BStop-Process calc
CStop-Process -Id calc
DStop-Process -Name calc
Attempts:
2 left
💡 Hint
Check the parameter names for Stop-Process.
🔧 Debug
advanced
2:00remaining
Why does this script fail to stop the process?
You run this script to stop a process named 'example':

$proc = Get-Process example
Stop-Process $proc


But it throws an error. What is the cause?
AStop-Process expects process Id or name, not a process object
BYou need to convert $proc to string before passing
CStop-Process requires the -Name parameter explicitly
DGet-Process did not find any process named 'example'
Attempts:
2 left
💡 Hint
Check what type of input Stop-Process accepts.
🚀 Application
advanced
2:30remaining
How to safely stop a process only if it is running?
You want to stop a process named 'myapp' only if it is currently running, without causing errors if it is not. Which script snippet achieves this?
AGet-Process -Name myapp | Stop-Process
BStop-Process -Name myapp -ErrorAction SilentlyContinue
Cif (Get-Process -Name myapp -ErrorAction SilentlyContinue) { Stop-Process -Name myapp }
DStop-Process -Name myapp -Force
Attempts:
2 left
💡 Hint
Think about checking existence before stopping.
🧠 Conceptual
expert
1:30remaining
What is the effect of using Stop-Process with the -Force parameter?
In PowerShell, what does the -Force parameter do when used with Stop-Process?
AIt forces the process to stop immediately, ignoring any prompts or errors
BIt only stops processes running with administrator privileges
CIt delays stopping the process until all child processes are stopped
DIt logs the stop action but does not actually stop the process
Attempts:
2 left
💡 Hint
Consider what 'force' usually means in commands.

Practice

(1/5)
1. What does the PowerShell command Get-Process do?
easy
A. Lists all running processes on the computer
B. Stops a running process immediately
C. Starts a new process
D. Deletes a file from the system

Solution

  1. Step 1: Understand the purpose of Get-Process

    The command Get-Process is used to display information about processes currently running on the computer.
  2. Step 2: Compare options with command function

    Only Lists all running processes on the computer correctly describes listing running processes. Other options describe different actions not related to Get-Process.
  3. Final Answer:

    Lists all running processes on the computer -> Option A
  4. Quick Check:

    Get-Process lists processes = A [OK]
Hint: Get-Process always shows running programs, not stopping them [OK]
Common Mistakes:
  • Confusing Get-Process with Stop-Process
  • Thinking Get-Process starts or deletes processes
  • Assuming it modifies processes instead of listing
2. Which of the following is the correct syntax to stop a process named 'notepad' in PowerShell?
easy
A. Stop-Process notepad -Force
B. Get-Process -Stop notepad
C. Kill-Process -Name notepad
D. Stop-Process -Name notepad

Solution

  1. Step 1: Identify correct cmdlet and parameter

    The cmdlet to stop a process is Stop-Process. The parameter to specify process by name is -Name.
  2. Step 2: Validate syntax correctness

    Stop-Process -Name notepad uses correct cmdlet and parameter: Stop-Process -Name notepad. Get-Process -Stop notepad uses wrong cmdlet and parameter. Stop-Process notepad -Force misses the parameter name before 'notepad'. Kill-Process -Name notepad uses a non-existent cmdlet.
  3. Final Answer:

    Stop-Process -Name notepad -> Option D
  4. Quick Check:

    Stop-Process with -Name is correct syntax = C [OK]
Hint: Use Stop-Process with -Name to stop by process name [OK]
Common Mistakes:
  • Omitting the -Name parameter
  • Using incorrect cmdlet names like Kill-Process
  • Placing process name without parameter name
3. What will be the output of this PowerShell command?
Get-Process -Name powershell | Stop-Process -PassThru
medium
A. Lists all running PowerShell processes without stopping them
B. Stops the PowerShell process and outputs the stopped process details
C. Throws an error because Stop-Process cannot be piped
D. Starts a new PowerShell process

Solution

  1. Step 1: Understand the pipeline usage

    The command gets the process named 'powershell' and pipes it to Stop-Process. The -PassThru parameter makes Stop-Process output the stopped process object.
  2. Step 2: Predict command behavior

    The process will be stopped, and its details will be shown as output. No error occurs because piping is supported.
  3. Final Answer:

    Stops the PowerShell process and outputs the stopped process details -> Option B
  4. Quick Check:

    Get-Process piped to Stop-Process with -PassThru stops and outputs = B [OK]
Hint: Stop-Process supports pipeline input and -PassThru outputs stopped process [OK]
Common Mistakes:
  • Thinking Stop-Process cannot accept pipeline input
  • Assuming it only lists processes without stopping
  • Confusing -PassThru as a force stop
4. You run this command but get an error:
Stop-Process -Name

What is the problem and how to fix it?
medium
A. The command should be Get-Process -Name instead
B. Stop-Process does not use -Name; use -Id instead
C. Missing process name after -Name; add the process name
D. Stop-Process requires -Force parameter always

Solution

  1. Step 1: Identify the error cause

    The command uses -Name parameter but does not specify the process name, causing a syntax error.
  2. Step 2: Correct the command

    To fix, provide the process name after -Name, for example: Stop-Process -Name notepad.
  3. Final Answer:

    Missing process name after -Name; add the process name -> Option C
  4. Quick Check:

    Parameter -Name needs a value = D [OK]
Hint: Always provide a value after -Name parameter [OK]
Common Mistakes:
  • Leaving -Name without a value
  • Assuming -Force is always required
  • Confusing Stop-Process with Get-Process
5. You want to stop all running instances of 'chrome' safely but only if they use more than 100 MB of memory. Which PowerShell command achieves this?
hard
A. Get-Process -Name chrome | Where-Object { $_.WorkingSet -gt 100000000 } | Stop-Process
B. Get-Process -Name chrome | Where-Object { $_.WorkingSet -gt 100MB } | Stop-Process
C. Stop-Process -Name chrome -MemoryLimit 100MB
D. Get-Process chrome | Stop-Process -MemoryUsage 100MB

Solution

  1. Step 1: Understand memory property and filtering

    The WorkingSet property shows memory usage in bytes. 100 MB equals 100,000,000 bytes approximately.
  2. Step 2: Filter processes by memory and stop them

    Get-Process -Name chrome | Where-Object { $_.WorkingSet -gt 100000000 } | Stop-Process correctly filters chrome processes with memory usage greater than 100,000,000 bytes and pipes them to Stop-Process. Get-Process -Name chrome | Where-Object { $_.WorkingSet -gt 100MB } | Stop-Process uses '100MB' which is invalid syntax. Options C and D use non-existent parameters.
  3. Final Answer:

    Get-Process -Name chrome | Where-Object { $_.WorkingSet -gt 100000000 } | Stop-Process -> Option A
  4. Quick Check:

    Memory in bytes filter with Where-Object = A [OK]
Hint: Memory is in bytes; use numeric value, not '100MB' string [OK]
Common Mistakes:
  • Using '100MB' as a value instead of bytes
  • Trying to use Stop-Process parameters that don't exist
  • Not filtering processes before stopping