---
title: "PowerShell Basics: Navigating CSV Files"
description: "Master CSV file handling in PowerShell for various scenarios. Read, parse, and manage data effectively using delimiters and headers. Boost your IT productivity."
canonical: "https://adamtheautomator.com/powershell-basics-navigating-csv-files/"
---

# PowerShell Basics: Navigating CSV Files

> Master CSV file handling in PowerShell for various scenarios. Read, parse, and manage data effectively using delimiters and headers. Boost your IT productivity.

Source: https://adamtheautomator.com/powershell-basics-navigating-csv-files/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![PowerShell Basics: Navigating CSV Files](https://adamtheautomator.com/wp-content/uploads/2024/05/Engaging-CSV-Handling-Blog-Cover.webp)

# PowerShell Basics: Navigating CSV Files

[![](https://secure.gravatar.com/avatar/d0b9d42e21e5622713f8b693aa5c0f9244d5f7dd200ed29b8398f52dee5de337?s=192&d=mm&r=g)Adam Bertram](https://adamtheautomator.com/author/adam-bertram/)15 May 20243 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[PowerShell](/tag/powershell/)

In this tutorial, we’re diving into the essentials of handling CSV files using PowerShell, covering a variety of scenarios you might encounter in the real world. This guide will help sysadmins and IT professionals manage data effectively, demonstrating the power and flexibility of PowerShell in working with different types of CSV files.

To set the stage, let’s create a simple CSV file to work with.

```
@(
	[pscustomobject]@{
		FirstName = 'Joe'
		LastName = 'Jones,Barrett'
		Address = '453 1st St'
		City = 'Phoenix'
		State = 'AZ'
	},
	[pscustomobject]@{
		FirstName = 'Jose'
		LastName = 'Melindez'
		Address = '5663 Main St'
		City = 'Atlanta'
		State = 'GA'
	}
) | Export-Csv -Path ~Employees.csv
```

And read it with Get-Content.

```
Get-Content -Path ~Employees.csv
```

![](https://adamtheautomator.com/wp-content/uploads/2024/05/untitled-6.png)

Nothing too fancy, just a CSV file with a couple of fictional employees. A few things to note that will come in handy later; notice this CSV file uses commas as field delimiters and quotes. The quotes enclose each field value, so you can even use the delimiter, a comma in this case, inside of the field value like the “Jones-Barrett” example. That’s one field.

Also, notice I used the `Get-Content` cmdlet. This cmdlet isn’t smart; it reads a text file by default and barfs out the content as an array of strings. Let’s check out the type of object `Get-Content` returns for each CSV row.

```
Get-Content -Path ~Employees.csv | Get-Member
```

![](https://adamtheautomator.com/wp-content/uploads/2024/05/untitled-7.png)

You’ll see that it returns a simple string. Actually, it’s an array of strings. If I use the not too common unary operator to prevent PowerShell from unrolling the array….

```
,(Get-Content -Path ~Employees.csv) | Get-Member
```

![](https://adamtheautomator.com/wp-content/uploads/2024/05/untitled-8.png)

You can see that Get-Content returns an array of objects which in this case are strings. It’s an array because of the left and right brackets.

If I look at a single object, you’ll see that it’s just the whole line of the CSV file, including the commas and quotes.

```
Get-Content -Path ~/Employees.csv | Select-Object -First 1
```

![](https://adamtheautomator.com/wp-content/uploads/2024/05/untitled-9.png)

We want objects, not raw strings, for each CSV file line. I want objects with fields as object properties. To get that, I can use the `Import-Csv` cmdlet.

```
Import-Csv -Path ~/Employees.csv
```

![](https://adamtheautomator.com/wp-content/uploads/2024/05/untitled-10.png)

That looks much better. It has intelligently parsed the entire CSV file, converted the header row in the CSV file to object property names, and used the field values as property values. Let’s check the object type now.

```
Import-Csv -Path ~/Employees.csv | Get-Member
```

![](https://adamtheautomator.com/wp-content/uploads/2024/05/untitled-11.png)

You can now see that the output object type is `System.Management.Automation.PSCustomObject`; not just a string. The `Import-Csv` cmdlet knew the CSV file’s structure and was able to convert it to a set of PSCustomObjects.

Here’s another type of CSV file you might run into.

```
Get-Content -Path ~Employees-withcommasnoquotes.csv
```

![](https://adamtheautomator.com/wp-content/uploads/2024/05/untitled-12.png)

Notice the difference? No quotes and notice the second row `Jones,Barrett`. That comma is actually part of Joe’s name. The value `Barrett` is not his address.

FYI: I created that CSV file with this code:

```
@(
	[pscustomobject]@{
		FirstName = 'Joe'
		LastName = 'Jones,Barrett'
		Address = '453 1st St'
		City = 'Phoenix'
		State = 'AZ'
	},
	[pscustomobject]@{
		FirstName = 'Jose'
		LastName = 'Melindez'
		Address = '5663 Main St'
		City = 'Atlanta'
		State = 'GA'
	}
) | Export-Csv -Path ~Employees.csv

(Get-Content -Path ~Employees.csv).replace('"','') | Set-Content -Path ~Employees-withcommasnoquotes.csv
```

Let’s see how `Import-Csv` handles this.

```
Import-Csv -Path ~Employees-withcommasnoquotes.csv
```

![](https://adamtheautomator.com/wp-content/uploads/2024/05/untitled-13.png)

That’s not right. All of the field values to the right of the `LastName` field are wrong. `Import-Csv` is using that comma in his name as a field delimiter. And this is where the quotes come in. Quotes define the entirety of a field, the delimiter tells Import-Csv where a field ends and begins.

Let’s shift gears and now cover one scenario you may find yourself in. Recall that I mentioned earlier that a CSV should _technically_ have fields delimited by commas. Well, sometimes you’ll find “CSV” files with different delimiters like tabs. By default, the `Import-Csv` cmdlet doesn’t like that.

For example, I have a CSV file here…

```
Import-Csv ~/Employeeswithtabs.csv
```

![](https://adamtheautomator.com/wp-content/uploads/2024/05/untitled-14.png)

Things don’t look right. `Import-Csv` hasn’t transformed each line into an object. That’s because it was looking for a comma as a field delimiter. If I look at this file…

```
Get-Content ~/Employeeswithtabs.csv
```

![](https://adamtheautomator.com/wp-content/uploads/2024/05/untitled-15.png)

You’ll see the fields are delimited by tabs and not commas. Luckily, there’s a quick fix. Simply use the `Delimiter` parameter.

```
Import-Csv ~/Employeeswithtabs.csv -Delimiter "`t"
```

![](https://adamtheautomator.com/wp-content/uploads/2024/05/untitled-16.png)

The output looks much better now. `Import-Csv` is now looking for tabs as field delimiters instead of commas and is parsing the CSV file correctly.

To round out this demo, let’s now cover one more scenario; CSVs with no headers. Maybe you’ve been sent a CSV file from some ancient HR database with no headers that looks something like this.

```
Get-Content -Path ~Employees-noheaders.csv
```

![](https://adamtheautomator.com/wp-content/uploads/2024/05/untitled-17.png)

When you attempt to read the CSV with `Import-Csv`, this is what happens.

```
Import-Csv -Path ~Employees-noheaders.csv
```

![](https://adamtheautomator.com/wp-content/uploads/2024/05/untitled-18.png)

`Import-Csv` has no field names to associate with values, so it uses the top row as headers and makes them property names. This isn’t right. You could modify the CSV and add headers that way, but I always prefer to leave the files unchanged as much as possible. For `Import-Csv` to have valid headers, use the `Header` parameter.

```
Import-Csv -Path ~Employees-noheaders.csv -Header 'FirstName','LastName','Address','City','State'
```

![](https://adamtheautomator.com/wp-content/uploads/2024/05/untitled-19.png)

Much better! When you use the `Header` parameter and specify a comma-delimited list, `Import-Csv` uses that set of values from left to right as field names rather than the first row of the CSV file. This parameter allows you to parse CSV files with no headers without modifying the original file.

You should now be on your way to a much better experience reading CSV files with PowerShell!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-basics-navigating-csv-files%2F&text=PowerShell%20Basics%3A%20Navigating%20CSV%20Files)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-basics-navigating-csv-files%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-basics-navigating-csv-files%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/publisher/2e05d9c85b2b81feb24af1f04a889143/3eab14af9dabf46fbd333914ce6ccf46f84117d2394d3e7218c186cd249bb7e2.webp)

### [PowerShell or Power Automate: Stop Automation Mistakes](/powershell-vs-power-automate/)

Score six factors to choose between PowerShell and Power Automate: target system, complexity, data volume, team skills, cost, governance.

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26995-troubleshoot-dns-issues-powershell-codex.webp)

### [Troubleshoot DNS Issues with PowerShell](/troubleshoot-dns-issues-powershell/)

Troubleshoot DNS issues with PowerShell by testing name resolution, DNS client settings, cache entries, and network connectivity in a repeatable workflow.

![](https://adamtheautomator.com/wp-content/uploads/2025/10/image_2025-10-24_095322075.png)

### [Migrating from PowerShell 6 to 7.5: Breaking Changes/New Features](/migrating-powershell-6-to-7-5/)

Migrate from PowerShell Core 6 to 7.5: breaking changes, features, and testing tips.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
