How to create output csv with headers


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


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.

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.

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($
$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))</code> <code> $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.