Home > Net >  Csv data into table format using powershell
Csv data into table format using powershell

Time:11-19

I have taken data from csv file using get-content I need to print data in table format how can I do that? Csv data looks like this after printing it in the mail.

ID OP_ID STATE OUP_ID METHOD time ------------ -------- ----- ---------------- ---- 2187 ab8262 working ky981 IN 09.40.13.161000 2779 ab9128 working ky359 Out 89.9 09.52.04.962000 ```

Fyi:Data will be different every time

But I want to represent it as a table

CodePudding user response:

Why not just use something like this and immediately output it into a table with ft?

Import-CSV -Path c:\temp\test.csv | ft

ft is a built-in alias of the Format-Table cmdlet.

CodePudding user response:

The first line is considered as heading using Import-CSV:

$csvfile = Import-Csv -Path c:\temp\test.csv
$csvfile.Header1
$csvfile.Header2
$csvfile.Header3

Even if you want have a custom Header, then you can provide one:

Import-Csv -Path c:\temp\test.csv -Header 'Header1','Header2','Header3'
  • Related