Home > Back-end >  Powershell array in array to use in Out-GridView
Powershell array in array to use in Out-GridView

Time:07-12

I am trying to optimize how my logging file looks in an app I have developed. I'm currently using the following code:

$pro_arry = @(
"V 1.0      Initial Release          7 July 2022",
"V 1.1      Optimized Update functionality and added logging         9 July 2022"
)

it looks like such:

enter image description here

I would like to use something like a nested array in order to display the Version, Description, and Date in separate cells.

How would I go about doing this?

CodePudding user response:

enter image description hereAs formatted, this is all just one long string. Hence the results you are getting. You have to format each into their own property (thus column). OGV does a few neat things, but not everything. In those cases, you need to develop a code block or your own GUI.

OGV expects columnar data, just like databases and spreadsheets.

For example:

Clear-Host 
$pro_arry = @(
"V 1.0      Initial Release          7 July 2022",
"V 1.1      Optimized Update functionality and added logging         9 July 2022"
)

# Replace spaces with a comma and convert to csv with custom headers.
$pro_arry -replace '     *',',' | 
ConvertFrom-Csv -Header Version,Description,Date | 
Out-GridView -Title 'Product List' -PassThru
  • Related