- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 create dynamic columns (headers) in CSV using PowerShell?
To create dynamic columns or headers using CSV, we can use multiple methods but the one method that I find most suitable is the PSObject method.
Let assume that your CSV column headers depend on the input provided by the user. Input can be a text file, user prompt for headers, array, etc. For this example, we will use the text file as input.
We have the below columns (headers) to create in the CSV file.
We will use the below command to create headers using PSObject and then export them into the CSV file.
$object = New-Object psobject foreach($item in (gc C:\Temp\DynamicHeaders.txt)){ $object | Add-Member -MemberType NoteProperty $item -Value '' } $object | Export-Csv C:\Temp\Customheaders.csv -NoTypeInformation
Once you check the CSV file, it will be created as what we provided in the text file.
Output
- Related Articles
- How to retrieve CSV file headers using PowerShell?
- How to create a CSV file manually in PowerShell?
- How to edit the CSV file using PowerShell?
- How to convert JSON to CSV file using PowerShell?
- How to convert JSON file to CSV file using PowerShell?
- How to append data into a CSV file using PowerShell?
- How to use custom headers in the PowerShell output table?
- How to Sort CSV by multiple columns in Python ?
- How to Export and import CSV file manually in PowerShell?
- How to create a temporary file using PowerShell?
- Importing / Exporting CSV file in PowerShell
- How to create tab headers with CSS and JavaScript?
- How to create a new local group using PowerShell?
- How to create a self-signed certificate using PowerShell?
- How to create the Azure Storage context using PowerShell?

Advertisements