【发布时间】:2018-10-17 05:19:14
【问题描述】:
我有以下 powershell 代码:
clear;
$importedIDs = (Import-Csv "testing.csv" -Delimiter ';').id;
Write-Host $importedIDs.Length;
for ($i=0; $i -lt $importedIDs.Length; $i++) {
Write-Host $($importedIDs[$i]);
}
目标是只读取 csv 文件中的 id 列,如下所示:
"created";"id"
"2018-04-04 21:03:01";"123456"
"2018-04-04 21:03:01";"123457"
当有两行或更多行时,输出符合预期:
2
123456
123457
但是,当 csv 文件中只有 1 行(id 为 123456 的行)时,输出为:
6
1
2
3
4
5
6
期望的输出是:
1
123456
谁能解释为什么会发生这种情况以及我该如何解决这个问题? 任何帮助表示赞赏
【问题讨论】:
标签: windows powershell csv import powershell-3.0