0
0
PowerShellscripting~20 mins

CSV operations (Import-Csv, Export-Csv) in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
CSV operations (Import-Csv, Export-Csv)
📖 Scenario: You work in a small office where you need to manage employee data stored in CSV files. You want to automate reading this data, filtering it, and saving the filtered data back to a new CSV file.
🎯 Goal: Build a PowerShell script that imports employee data from a CSV file, filters employees based on their department, and exports the filtered data to a new CSV file.
📋 What You'll Learn
Use Import-Csv to read data from a CSV file
Create a variable to hold the department name to filter
Use a Where-Object filter to select employees from the specified department
Use Export-Csv to save the filtered data to a new CSV file
Print the filtered employee data to the console
💡 Why This Matters
🌍 Real World
Automating CSV data handling is common in office tasks like managing employee records, sales data, or inventory lists.
💼 Career
Knowing how to import, filter, and export CSV files with PowerShell is useful for system administrators, data analysts, and IT support professionals.
Progress0 / 4 steps
1
Import employee data from CSV
Write a line of PowerShell code to import employee data from a CSV file named employees.csv into a variable called employees using Import-Csv.
PowerShell
Need a hint?

Use Import-Csv with the -Path parameter to read the CSV file.

2
Set department filter
Create a variable called departmentFilter and set it to the string Sales to specify the department you want to filter.
PowerShell
Need a hint?

Assign the string 'Sales' to the variable departmentFilter.

3
Filter employees by department
Use Where-Object to filter employees where the Department property equals departmentFilter. Store the result in a variable called filteredEmployees.
PowerShell
Need a hint?

Use the pipeline | and Where-Object with a script block to compare Department to departmentFilter.

4
Export filtered data and display output
Export filteredEmployees to a CSV file named sales_employees.csv using Export-Csv with -NoTypeInformation. Then print filteredEmployees to the console.
PowerShell
Need a hint?

Use Export-Csv with -NoTypeInformation to save the filtered data. Then output the variable to display it.