How to import CSV file in PowerShell

It’s a common task to import values from a csv file and process them in a powershell script. Here’s how.

# Define the path to a user list as csv file
$filepath = "c:\users\\desktop\users.csv
$filecontent = Import-Csv -Path $filepath -Delimiter ";" 

# Filter the content by the column 'userlogin'
$userlogins = $filecontent | select userlogin 

foreach ($userlogin in $userlogins) {
    # Do something fancy with the userlogin

Some thoughts on this

In this example we assume a structure in the csv file like this one:


Though the ‘c’ in csv stands for comma, it is often the case that a different character is used as delimiter. So have a look inside of the file to check what is used in your case.

The rest is pretty straight forward. As I only need the userlogin values I can do a ‘select’ and work only with the userlogins.

So, enjoy your life and happy scripting…