Bird
0
0

What should you do to successfully remove all items?

medium📝 Debug Q6 of 15
PowerShell - File and Directory Operations
You attempt to delete all contents inside C:\Logs using Remove-Item -Path C:\Logs\* -Recurse but receive an error about access denied on some files. What should you do to successfully remove all items?
AUse <code>-Confirm</code> to prompt for each file deletion
BAdd the <code>-Force</code> parameter to override read-only or hidden attributes
CRun the command without <code>-Recurse</code> to avoid errors
DRestart PowerShell as a standard user
Step-by-Step Solution
Solution:
  1. Step 1: Identify the error cause

    Access denied errors often occur due to read-only or hidden file attributes.
  2. Step 2: Use -Force parameter

    The -Force parameter allows Remove-Item to delete hidden or read-only files.
  3. Step 3: Evaluate other options

    Use -Confirm to prompt for each file deletion only prompts for confirmation, not fixing errors. Run the command without -Recurse to avoid errors avoids recursion but won't delete subfolders. Restart PowerShell as a standard user reduces privileges, which won't help.
  4. Final Answer:

    Add the -Force parameter to override read-only or hidden attributes -> Option B
  5. Quick Check:

    Use -Force to delete protected files [OK]
Quick Trick: Use -Force to delete read-only or hidden files [OK]
Common Mistakes:
  • Ignoring the need for -Force with protected files
  • Removing -Recurse and missing subfolders
  • Running PowerShell without admin rights but not using -Force

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes