- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
- Related Articles
- How to create dynamic columns (headers) in CSV using PowerShell?
- How to convert JSON file to CSV file using PowerShell?
- How to edit the CSV file using PowerShell?
- How to convert JSON to CSV file using PowerShell?
- How to append data into a CSV file using PowerShell?
- How to create a CSV file manually in PowerShell?
- How to retrieve specific file(s) information using Get-ChildItem in PowerShell?
- Importing / Exporting CSV file in PowerShell
- How to Export and import CSV file manually in PowerShell?
- How to retrieve the content of the file in PowerShell?
- How to retrieve Azure VMs using PowerShell?
- How to retrieve certificate thumbprint using PowerShell?
- How to parse a CSV file using PHP
- How to retrieve files and folders attributes using PowerShell?
- How to retrieve tasks in Task scheduler using PowerShell?

Advertisements