为什么在这种情况下,where-object 不起作用?
$controlFlowArgs = @{ waitForEnter = $false }
$controlFlowArgs | Format-Table
$controlFlowArgs | Format-List
$result = $controlFlowArgs | Where-Object -FilterScript { $_.Name -eq "waitForEnter" }
$result
输出
Name Value # Format-Table
---- -----
waitForEnter False
Name : waitForEnter # Format-List
Value : False
# Missing result would be here
最佳答案
$controlFlowArgs 是一个哈希表。您可能应该有不同的想法。
$result = $controlFlowArgs | Where-Object { $_["waitForEnter"] }
会将$false
存储在$result
中。
否则你可以直接使用哈希表:
if ($controlFlowArgs["waitForEnter"]) {
...
}
关于powershell - Where-Object 不过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70159011/