Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell CSV Variable to Out-GridView

This is driving me nuts. I want to save CSV text to a string variable - NOT a file! I want to then output that (CSV) text to the Out-GridView using the commas as column separators.

How do I do this? I have looked high and low, and I can find nothing - NOTHING - on how to do this without saving the text to CSV file first then importing it using Import-Csv. I don't want to save a file, I just want to display my CSV formatted multiline string object (with NewLine characters) in the Out-GridView.

Any clues?

Example:

$rows += "COL1,COL2,COL3`n"    # CSV header row AS TEXT
$rows += "val1,val2,val3`n"    # CSV data row AS TEXT

$rows | Out-GridView           # does not work! No columns :( - just a single column per row
like image 564
digitalbunny Avatar asked Jul 28 '26 08:07

digitalbunny


1 Answers

Pipe $rows to ConvertFrom-Csv:

$rows += "COL1,COL2,COL3`n"
$rows += "val1,val2,val3`n"
$rows | ConvertFrom-Csv | Out-GridView

What you would normally want to do when creating a objects from a embebed CSV structured string instead of += is to use Here-Strings:

@'
COL1,COL2,COL3
val1,val2,val3
'@ | ConvertFrom-Csv | Out-GridView
like image 134
Santiago Squarzon Avatar answered Aug 01 '26 15:08

Santiago Squarzon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!