Bird
0
0

How can you safely stop a process named 'notepad' only if it is running, without causing errors if it is not found?

hard📝 Application Q9 of 15
PowerShell - System Administration
How can you safely stop a process named 'notepad' only if it is running, without causing errors if it is not found?
AStop-Process -Name notepad
BGet-Process -Name notepad -ErrorAction SilentlyContinue | Stop-Process
CStop-Process -Name notepad -Force
DGet-Process -Name notepad ; Stop-Process -ErrorAction SilentlyContinue
Step-by-Step Solution
Solution:
  1. Step 1: Use Get-Process with error handling

    Get-Process -Name notepad -ErrorAction SilentlyContinue avoids errors if notepad is not running.
  2. Step 2: Pipe to Stop-Process

    Piping the result to Stop-Process stops the process only if it exists.
  3. Final Answer:

    Get-Process -Name notepad -ErrorAction SilentlyContinue | Stop-Process -> Option B
  4. Quick Check:

    Use Get-Process with error handling before stopping [OK]
Quick Trick: Use -ErrorAction SilentlyContinue to avoid errors if process missing [OK]
Common Mistakes:
  • Using Stop-Process directly without checking process existence
  • Misplacing -ErrorAction parameter
  • Assuming -Force prevents errors if process missing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes