0
0
PowerShellscripting~20 mins

CSV operations (Import-Csv, Export-Csv) in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
CSV Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Import-Csv command?
Given a CSV file named data.csv with the following content:
Id,Name,Age
1,Alice,30
2,Bob,25

What will be the output of this PowerShell command?
Import-Csv -Path 'data.csv' | ForEach-Object { $_.Name }
PowerShell
Import-Csv -Path 'data.csv' | ForEach-Object { $_.Name }
A
Id
Name
Age
B
Alice
Bob
C
30
25
D
1
2
Attempts:
2 left
💡 Hint
Import-Csv reads the CSV and creates objects with properties matching the headers.
💻 Command Output
intermediate
2:00remaining
What does this Export-Csv command produce?
Consider this PowerShell code:
$data = @(
  @{Id=1; Name='Alice'; Age=30},
  @{Id=2; Name='Bob'; Age=25}
)
$data | Export-Csv -Path 'output.csv' -NoTypeInformation

What will be the content of output.csv?
PowerShell
$data = @(@{Id=1; Name='Alice'; Age=30}, @{Id=2; Name='Bob'; Age=25})
$data | Export-Csv -Path 'output.csv' -NoTypeInformation
A
Id,Name,Age
1,Alice,30
2,Bob,25
B
@{Id=1; Name=Alice; Age=30}
@{Id=2; Name=Bob; Age=25}
C
"Id","Name","Age"
"1","Alice","30"
"2","Bob","25"
D
TypeId
System.Management.Automation.PSCustomObject
System.Management.Automation.PSCustomObject
Attempts:
2 left
💡 Hint
Export-Csv outputs CSV with quoted values by default and includes headers.
🔧 Debug
advanced
2:00remaining
Why does this Import-Csv command fail?
You run this command:
Import-Csv -Path 'missing.csv'

But you get an error:
Import-Csv : Cannot find path 'missing.csv' because it does not exist.
What is the cause?
PowerShell
Import-Csv -Path 'missing.csv'
AThe file 'missing.csv' does not exist in the current directory.
BImport-Csv cannot read CSV files with .csv extension.
CThe command requires -Delimiter parameter to work.
DPowerShell does not support Import-Csv on Windows.
Attempts:
2 left
💡 Hint
Check if the file path is correct and the file exists.
🚀 Application
advanced
2:00remaining
How to filter CSV rows with Import-Csv and Export-Csv?
You have a CSV file users.csv with columns: Id, Name, Age.
You want to create a new CSV adults.csv containing only rows where Age is 18 or more.
Which PowerShell command does this correctly?
AImport-Csv users.csv | ForEach-Object { if ($_.Age -ge 18) { $_ } } | Export-Csv adults.csv
BImport-Csv users.csv | Where-Object { $_.Age -lt 18 } | Export-Csv adults.csv
CGet-Content users.csv | Where { $_ -ge 18 } | Export-Csv adults.csv
DImport-Csv users.csv | Where-Object { [int]$_.Age -ge 18 } | Export-Csv adults.csv -NoTypeInformation
Attempts:
2 left
💡 Hint
Use Where-Object to filter and Export-Csv with -NoTypeInformation to save.
🧠 Conceptual
expert
2:00remaining
What is the effect of the -NoTypeInformation parameter in Export-Csv?
When using Export-Csv in PowerShell, what does the -NoTypeInformation parameter do?
AIt prevents adding a type information line at the top of the CSV file.
BIt disables exporting the header row with column names.
CIt encrypts the CSV file to protect data.
DIt converts all data to string before exporting.
Attempts:
2 left
💡 Hint
Check the first line of CSV files exported with and without this parameter.