Supporting lexical-scope ScriptBlock parameters (e.g. Where-Object)
问题 Consider the following arbitrary function and test cases: Function Foo-MyBar { Param( [Parameter(Mandatory=$false)] [ScriptBlock] $Filter ) if (!$Filter) { $Filter = { $true } } #$Filter = $Filter.GetNewClosure() Get-ChildItem "$env:SYSTEMROOT" | Where-Object $Filter } ################################## $private:pattern = 'T*' Get-Help Foo-MyBar -Detailed Write-Host "`n`nUnfiltered..." Foo-MyBar Write-Host "`n`nTest 1:. Piped through Where-Object..." Foo-MyBar | Where-Object { $_.Name -ilike