Bird
0
0

You run this command to delete a registry key:

medium📝 Debug Q14 of 15
PowerShell - System Administration
You run this command to delete a registry key:
Remove-Item -Path 'HKCU:\Software\MyApp'

But it fails with an error saying the key is not empty. How can you fix this?
AAdd the parameter <code>-Recurse</code> to delete all subkeys
BUse <code>Remove-ItemProperty</code> instead
CRun <code>New-Item</code> to recreate the key first
DChange the path to <code>HKLM:\Software\MyApp</code>
Step-by-Step Solution
Solution:
  1. Step 1: Understand Remove-Item behavior

    Remove-Item cannot delete a key if it has subkeys unless -Recurse is used.
  2. Step 2: Apply -Recurse parameter

    Adding -Recurse deletes the key and all its subkeys, fixing the error.
  3. Final Answer:

    Add the parameter -Recurse to delete all subkeys -> Option A
  4. Quick Check:

    Remove-Item -Recurse deletes key with subkeys [OK]
Quick Trick: Use -Recurse with Remove-Item to delete keys with subkeys [OK]
Common Mistakes:
  • Using Remove-ItemProperty which deletes values, not keys
  • Trying to recreate key before deleting
  • Changing registry hive path without reason

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes