我正在尝试显示从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...
如何显示其他数组属性(列?)而不是空行?