简体   繁体   中英

Powershell array in array to use in Out-GridView

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:

在此处输入图像描述

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?

在此处输入图像描述 As 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM