Bird
0
0

This script throws an error:

medium📝 Debug Q7 of 15
PowerShell - File and Directory Operations
This script throws an error:
$csv = Import-Csv -Path users.csv
$csv | Export-Csv -Path users.csv -NoTypeInformation

Why?
AMissing pipeline operator before Export-Csv
BCannot read and write the same file simultaneously
CExport-Csv requires -Append parameter
DImport-Csv output is not compatible with Export-Csv
Step-by-Step Solution
Solution:
  1. Step 1: Identify file conflict

    Reading and writing the same file at once causes file lock or overwrite errors.
  2. Step 2: Understand Export-Csv behavior

    Export-Csv tries to overwrite users.csv while Import-Csv still holds it open.
  3. Final Answer:

    Cannot read and write the same file simultaneously -> Option B
  4. Quick Check:

    Same file read/write causes errors [OK]
Quick Trick: Avoid reading and writing the same CSV file simultaneously [OK]
Common Mistakes:
  • Thinking pipeline operator is missing
  • Assuming -Append fixes overwrite
  • Believing Import-Csv output is incompatible

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes