Accept where clause in an advanced function Accept where clause in an advanced function powershell powershell

Accept where clause in an advanced function


As ansgar-wiechers stated in the above comment, you have to remove the outer scriptblock literal ({}):

$Fruits = @(    @{        Name  = 'Kiwi'        Color = 'Green'    }    @{        Name  = 'Banana'        Color = 'Yellow'    })Function Get-Stuff {    Param (        [scriptblock]$Filter,        [hashtable[]]$Collection    )    # Subexpression removed.    $Collection.Where($Filter)}Get-Stuff -Filter { $_.Name -eq 'Kiwi' } -Collection $Fruits