I'm trying to figure out a way to incorporate a filter into a custom function and I haven't been able to get it working:
Function Test-Me{
Param
(
$Filter = "Number -like ""Three"""
)
$Obj = New-Object PSObject -Properties &{
Number = "One","Two","Three"
}
If($Filter){
$Obj | Where-Object $Filter
}else{
$Obj
}
}
I've tried various means, but they all fail:
$Filter = 'Where-Object{$_' + $Filter + '}'
$Obj | & $Filter
.
$Filter = "Number -like ""One"""
$Obj | Where & $Filter
How do you incorporate Filter support into custom functions?