gpt4 book ai didi

powershell - 使用PowerShell创建第五列作为列表

转载 作者:行者123 更新时间:2023-12-02 23:56:07 25 4
gpt4 key购买 nike

我必须在数组中添加第五列,但是当我运行脚本时,它给了我:

Column1 : Column2 : Column3 : Column4 : Column5 :

I would like to get this:

Column1  Column2   Column3   Column4  Column5-------  -------   -------   -------  -------

The code I'm using allows to display four columns and remove the matching cells in the array.

$csv = Import-Csv .\test1.csv -Delimiter ';'

$ref = [ordered]@{}
$columns = foreach ($i in 0..7) { ,[Collections.ArrayList]@() }

foreach ($row in $csv) {
$value = $row.Column1
$ref[$value] = $true
$columns[0].add($value) >$null
}

foreach ($row in $csv) {
$i = 1
foreach ($col in 'Column2', 'Column3', 'Column4') {
$value = $row.$col
if (!$ref[$value]) {
$columns[$i].add($value) >$null
}
$i++
}
}

$maxLine = ($columns | select -expand Count | measure -Maximum).Maximum - 1
$csv = foreach ($i in 0..$maxLine) {
[PSCustomObject]@{
Column1 = $columns[0][$i]
Column2 = $columns[1][$i]
Column3 = $columns[2][$i]
Column4 = $columns[3][$i]

}
}


$csv

列表是分别构建的,然后在这种情况下加入。

最佳答案

您可能正在寻找Format-Table cmdlet:

$csv | Format-Table

关于powershell - 使用PowerShell创建第五列作为列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44714235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com