Bird
0
0

What will be the result of running this PowerShell code?

medium📝 Command Output Q4 of 15
PowerShell - File and Directory Operations
What will be the result of running this PowerShell code?
Copy-Item -Path 'C:\Docs\file.txt' -Destination 'C:\Backup' -Force
AThrows an error because -Force is invalid here
BCopies file.txt to C:\Backup, overwriting if it exists
CDeletes file.txt from C:\Docs
DMoves file.txt to C:\Backup without keeping original
Step-by-Step Solution
Solution:
  1. Step 1: Understand Copy-Item with -Force

    Copy-Item copies the file to the destination. The -Force parameter allows overwriting existing files.
  2. Step 2: Confirm behavior

    The original file remains in C:\Docs. No deletion or move occurs.
  3. Final Answer:

    Copies file.txt to C:\Backup, overwriting if it exists -> Option B
  4. Quick Check:

    Copy-Item with -Force overwrites destination [OK]
Quick Trick: -Force overwrites existing files when copying [OK]
Common Mistakes:
  • Thinking -Force deletes original file
  • Confusing Copy-Item with Move-Item
  • Assuming -Force is invalid with Copy-Item

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes