我正在尝试显示从 CSV 文件生成的数组中每一列的唯一值。
CSV 文件包含:
ENV,RELEASE,SERVERNAME
DEVL,2008,winhost01
DEVL,2008,winhost02
DEVL,2014,winhost03
DEVL,2016,winhost04
TEST,2008,winhost05
TEST,2014,winhost06
PROD,2008,winhost07
PROD,2014,winhost08
PROD,2014,winhost09
PROD,2014,winhost10
预期输出:
ENV
---
DEVL
TEST
PROD
RELEASE
---
2008
2014
2016
SERVERNAME
---
winhost01
winhost02
..etc..
winhost10
我遍历数组中的每个属性,打印出这些值。我在第一个循环中得到第一列的值,但之后的每一列都只打印一个空行(准确地说是 16 个空行)。
$arrayin = Import-Csv "Documents\Powershell\test.csv";
$cols = $arrayin[0].psobject.properties.name;
$i = 0;
do {
$arrayin | Select-Object -Property $cols[$i] -Unique;
$i++;
} until ($i -eq $cols.count)
实际输出:
ENV
---
DEVL
TEST
PROD
...16 empty lines follow...
如何显示其他数组属性(列?)而不是空行?