Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to retrieve CSV file headers using PowerShell?
To retrieve the CSV file headers using PowerShell, we need to use the hidden property PSObject once we use to import the CSV file. We have a CSV file stored at the C:\temp\VMTags.csv and we need to retrieve its headers. The CSV file is as below.
| A | B | C | D |
|---|---|---|---|
| For | Patching_Day | Application | Owner |
| Ansible | Sunday | SecretTag | Chirag |
Importing the CSV file,
PS C:\> $csv = Import-Csv C:\Temp\VMTags.csv PS C:\> $csv For Patching_Day Application Owner --- ------------ ----------- ----- Ansible Sunday SecretTag Chirag
Example
Accessing hidden property,
PS C:\> $csv.psobject
Output

We need to use Properties to get our values. We will get all the headers here.
PS C:\> $csv.psobject.Properties | Select Name Name ---- For Patching_Day Application Owner
To get all the header values,
PS C:\> $csv.psobject.Properties | Select Value Value ----- Ansible Sunday SecretTag Chirag
Advertisements
