# How to create output csv with headers

**URL:** <https://forums.powershell.org/t/how-to-create-output-csv-with-headers/15143>\
**Category:** PowerShell Help\
**Created:** [October 25, 2020, 3:55pm UTC](https://forums.powershell.org/t/how-to-create-output-csv-with-headers/15143 "2020-10-25T15:55:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![palmero](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/palmero/32/1097_2.png) [@palmero](https://forums.powershell.org/u/palmero)\
**Post date:** [October 25, 2020, 3:55pm UTC](https://forums.powershell.org/t/how-to-create-output-csv-with-headers/15143/1 "2020-10-25T15:55:07Z")

</div>

Hello,

I am trying for format file system information from a VNX using PS with the plink command. I have the following code that returns the below output.

`$values = plink user@host -batch -i mycreds.ppk “export ‘NAS_DB=/nas’; /nas/bin/nas_fs -query:inuse=y:type=uxfs:isroot=false -fields:Name,SizeValues -format:‘%s,%s\n’”`  
``

`foreach($val in $values) {`  
` Write-Host $val`  
`}`

`Cifs01_FS,3036900,361855,2675044,88,3109785976`  
`Cifs02_FS,5641353,1577535,4063818,72,5776746416`  
`Cifs03_FS,1970,1968,2,0,2018032`

The Write-Host command returns the correct output, but if I export to csv, I end up with just the lengths. I would like to export to csv correctly and to add some headers as well. It would also be great to assign names to each field to do some math and make it more legible.

Any suggestions greatly appreciated.

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [October 25, 2020, 5:42pm UTC](https://forums.powershell.org/t/how-to-create-output-csv-with-headers/15143/2 "2020-10-25T17:42:27Z")

</div>

You’re not showing how you export it. I’ll assume it includes your write-host. Drop the write host and just try this.

```
$values | ConvertFrom-Csv -Header Header1,Header2,Header3,Header4,Header5,Header6 |
    Export-Csv -Path C:\Some\path\to.csv -NoTypeInformation
```

I wasn’t sure what the values meant so just update the headers accordingly and this should work.

---

<div class="post-metadata">

**Author:** ![palmero](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/palmero/32/1097_2.png) [@palmero](https://forums.powershell.org/u/palmero)\
**Post date:** [October 25, 2020, 7:36pm UTC](https://forums.powershell.org/t/how-to-create-output-csv-with-headers/15143/3 "2020-10-25T19:36:49Z")

</div>

You gave me the answer. It did not cross my mind to use the ConvertFrom-Csv. Once you made that suggestion, I was able to get what I wanted. Here is the final script:

`$OutTable = @()`  
`$values = plink user@host -batch -i mycreds.ppk “export ‘NAS_DB=/nas’; /nas/bin/nas_fs -query:inuse=y:type=uxfs:isroot=false -fields:Name,SizeValues -format:‘%s,%s\n’”`  
`$values | ConvertFrom-Csv -Header CIFS,Allocated,Consumed,Free,PCTFull,Blocks | `  
` ForEach-Object {`  
` $ReptObj = New-Object PSObject`  
` $ReptObj | Add-Member -Type NoteProperty -Name “Array” -Value “ArrayOne” #Fixed value`  
` $ReptObj | Add-Member -Type NoteProperty -Name “CIFsName” -Value $.CIFS`  
 _` $ReptObj | Add-Member -Type NoteProperty -Name “AllocatedTB” -Value ([math]::Round($`_`.Allocated/1e+6,2))`  
` $ReptObj | Add-Member -Type NoteProperty -Name “ConsumedTB” -Value ([math]::Round($i.Consumed/1e+6,2))`  
` $ReptObj | Add-Member -Type NoteProperty -Name “FreeTB” -Value ([math]::Round($i.Free/1e+6,2))&lt;/code&gt; &lt;code&gt; $ReptObj | Add-Member -Type NoteProperty -Name "PCTFull" -Value $i.PCTFull`  
` $OutTable += $ReptObj`  
` } `  
`$OutTable | Export-Csv -Path C:\temp.csv -NoTypeInformation`

The output csv now has the headers and storage sizes converted to TBs.

Your help is greatly appreciated.

&nbsp;

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:28pm UTC](https://forums.powershell.org/t/how-to-create-output-csv-with-headers/15143/4 "2024-05-16T20:28:41Z")

</div>


