skip to Main Content

Import CSV delimiter PowerShell

Why do we need to use the import CSV (comma-separated values) delimiter in PowerShell? By default, PowerShell uses a comma as a delimiter. Are you using a different delimiter then a comma in the CSV file? If yes, you need to make use of the delimiter parameter in PowerShell. In this article, you will learn how to work with the Import-Csv delimiter in PowerShell.

Information

A CSV file is an excellent combination with PowerShell. The Import-Csv cmdlet creates table-like custom objects from the items in CSV files. Each column in the CSV file becomes a property of the custom object, and the items in rows become the property values. Import-Csv works on any CSV file, including files that are generated by the Export-Csv cmdlet.

We like to run a PowerShell script to Create Active Directory Users from CSV with PowerShell. After running the script, an error is showing up.

Why is it happening?

Some European spreadsheet programs use semicolons rather than commas to separate (delimit) data fields in CSV files. It can cause problems with CSV imports.

Separating characters:

  • Semicolon:  ; 
  • Comma:  , 

Check Import-Csv cmdlet in PowerShell

Download NewUsersFinal.csv and place it in C:\Temp\ folder. Make use of the Import-Csv cmdlet. If you don’t see the columns in PowerShell, it means that it can’t read the CSV file properly.

If you don’t see all the information in the output, make use of the Out-GridView cmdlet.

It will show as below screen.

Import CSV delimiter PowerShell wrong

Add the delimiter parameter -Delimiter ”;” to the Import-Csv cmdlet.

Again, this time with the Out-GridView cmdlet.

Import CSV delimiter PowerShell right

Add delimiter parameter to Import-Csv cmdlet

As seen in the previous step, the CSV file got the character semicolon. We have to add the delimiter parameter -Delimiter “;” to the Import-Csv cmdlet.

Before

After

Run the script, it will work as expected. Did this help you?

Keep reading: Export a list of mailboxes to CSV in Exchange »

Conclusion

In this article, you learned how to import CSV delimiter with PowerShell. Check your CSV file and adjust your Import-Csv cmdlet with the delimiter parameter. It’s always good to import the CSV in PowerShell before running the script. This way, you know if the CSV file is readable!

Did you enjoy this article? If so, you may like the article New-MailboxExportRequest is not recognized in Exchange Server. Don’t forget to follow us and share this article.

ALI TAJRAN

ALI TAJRAN

ALI TAJRAN is a passionate IT Architect, IT Consultant, and Microsoft Certified Trainer. He started Information Technology at a very young age, and his goal is to teach and inspire others. Read more »

This Post Has 0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top