考虑下面的代码
$users = get-aduser -filter $filter -properties samAccountName,lastLogonTimestamp
$users|foreach -parallel {
[do something with $_.samAccountName] # --> this works fine. samAccountName can be read properly
[do something with $_.lastLogonTImestmp] # --> this doesn't work. lastLogonTimestamp is always NULL regardless if it is actually populated
}
同样的问题阅读 whenChanged,whenCreated。我在这里想念什么?
注意:这个问题不是关于引用外部变量的。这是关于管道中对象的属性可见性,它应该在脚本块中完全可访问。
非并行风格中的相同代码工作正常
$users = get-aduser -filter $filter -properties samAccountName,lastLogonTimestamp
$users|foreach {
[do something with $_.samAccountName] # --> this works fine. samAccountName can be read properly
[do something with $_.lastLogonTImestmp] # --> this also always works
}