好的 - 这是一个非常奇怪的问题 - 它可能有一个非常愚蠢的解决方案。无法在foreach循环中调用数组标题
但我导入CSV
$csv = import-csv c:\users\hello.csv
然后,我有话阵列,对此我想使用通过CSV搜索 - 如果有一个在CSV比赛 - 填充相邻的列在csv。
这里的数组:
$newhandles
hi
hello
现在 - 如果我运行foreach循环使用它内部的if语句 - 它不承认的标题之一。
foreach ($newhandle in $newhandles)
{if ($csv.name -eq $newhandle) {$csv.redundant = $newhandle}}
但是它给了我这个错误:
The property 'redundant' cannot be found on this object. Verify that the property exists
and can be set.
At line:1 char:69
+ ... andles) {if ($csv.name -eq $newhandle) {$csv.redundant = $newhandle}}
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyAssignmentException
我知道属性存在 - 因为如果我直接调用它 - 它显示了三个空的插槽 - 如果我直接调用的东西吧 - 元素将填充。如
> $csv[0].redundant = 'hi'
> $csv[0]
name : hi
description : don't settle
system : sight
redundant : hi
tags :
任何想法?
手动检查你追加[0],但如果你在它的工作原理SIM卡层层引用整个$ csv.Name。当您手动输入$ csv.Name时会发生什么? – LotPings