
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Create Dynamic Column 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
Advertisements