Bird
0
0

What will be the output of this PowerShell command if the file secret.txt is hidden and read-only?

medium📝 Command Output Q13 of 15
PowerShell - File and Directory Operations
What will be the output of this PowerShell command if the file secret.txt is hidden and read-only?

Remove-Item -Path 'C:\temp\secret.txt'
AFile is renamed to secret.txt.old
BFile is deleted successfully
CFile is moved to Recycle Bin
DError: Access to the file is denied
Step-by-Step Solution
Solution:
  1. Step 1: Understand default Remove-Item behavior on protected files

    By default, Remove-Item cannot delete hidden or read-only files without the -Force parameter.
  2. Step 2: Predict the command result

    Since -Force is missing, PowerShell will throw an access denied error when trying to delete the protected file.
  3. Final Answer:

    Error: Access to the file is denied -> Option D
  4. Quick Check:

    Missing -Force causes access denied error [OK]
Quick Trick: Use -Force to delete hidden or read-only files [OK]
Common Mistakes:
  • Assuming file deletes without -Force
  • Thinking Remove-Item moves files to Recycle Bin
  • Confusing rename with delete

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes