我认为问题的出现是因为
$dom
在第二次迭代中传入时,最终成为一个包含两个元素的数组。一个(肮脏的)修复方法是使用
Select-Object
仅获取第一个元素(建议使用
Select
而不是
[0]
因此,如果不是数组,则不会出错):
if($SecondQuery -eq $false) {
if($Property -ne $false -and $Property -ne '*') {
return $result.$Property
} else {
return $result
}
} else {
return Query-ComDomElements -Query $SecondQuery -Dom ($result | select -first 1) -Property $Property
}