0
0
PowerShellscripting~10 mins

CSV operations (Import-Csv, Export-Csv) in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import a CSV file named 'data.csv' into a variable.

PowerShell
$data = [1] -Path 'data.csv'
Drag options to blanks, or click blank then click option'
AImport-Csv
BExport-Csv
CConvertTo-Csv
DGet-Content
Attempts:
3 left
💡 Hint
Common Mistakes
Using Export-Csv instead of Import-Csv.
Using Get-Content which reads raw text, not objects.
2fill in blank
medium

Complete the code to export the variable $data to a CSV file named 'output.csv' without type information.

PowerShell
$data | [1] -Path 'output.csv' -NoTypeInformation
Drag options to blanks, or click blank then click option'
AConvertTo-Csv
BImport-Csv
CExport-Csv
DOut-File
Attempts:
3 left
💡 Hint
Common Mistakes
Using Import-Csv instead of Export-Csv.
Using ConvertTo-Csv which outputs CSV text but does not save to file.
3fill in blank
hard

Fix the error in the code to import 'records.csv' and select only the 'Name' column.

PowerShell
$names = [1] -Path 'records.csv' | Select-Object Name
Drag options to blanks, or click blank then click option'
AExport-Csv
BGet-Content
CConvertTo-Csv
DImport-Csv
Attempts:
3 left
💡 Hint
Common Mistakes
Using Get-Content which reads raw text, not objects.
Using Export-Csv which writes CSV files.
4fill in blank
hard

Fill both blanks to filter imported CSV data where Age is greater than 30.

PowerShell
$filtered = [1] -Path 'people.csv' | Where-Object { $_.Age [2] 30 }
Drag options to blanks, or click blank then click option'
AImport-Csv
BExport-Csv
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using Export-Csv instead of Import-Csv.
Using '<' instead of '>' for the age comparison.
5fill in blank
hard

Fill all three blanks to create a CSV from $users with only 'Username' and 'Email' where 'Active' is true.

PowerShell
$activeUsers = { [1]: [2], Email: $_.Email for [3] in $users if $_.Active } | Export-Csv -Path 'active.csv' -NoTypeInformation
Drag options to blanks, or click blank then click option'
AUsername
B$_.Username
Cuser
DEmail
Attempts:
3 left
💡 Hint
Common Mistakes
Using $_ instead of a variable name in the loop.
Not matching keys and values correctly in the hashtable.