If you want to use it with where-object, define OnlyEven as a function, not
a filter:
PS> function onlyEven {
>> $_ %2 -eq 0
>> }
>>
PS> 1..6 | where {onlyEven}
2
4
6
Jacques
"Andrew Watt [MVP]" <SVGDeveloper@aol.com> wrote in message
news:i5uel295kt0lbsoas2bc3d5iq1r44up4rk@4ax.com...
>I must be doing something very basic wrong here but just can't see it.
>
> I'm trying to create a simple filter to filter out odd numbered
> values.
>
> The code works when inside the script block of where-object.
>
> PS Alias:\> 1,2,3,4,5,6 | where-object {$_ % 2 -eq 0}
> 2
> 4
> 6
>
> I copied and pasted it to the Filter definition:
>
> PS Alias:\> Filter OnlyEven {
>>> $_ % 2 -eq 0
>>> }
>>>
>
> And ran it as follows (when it didn't filter).
>
> PS Alias:\> 1,2,3,4,5,6 | where-object {OnlyEven}
> 1
> 2
> 3
> 4
> 5
> 6
>
> However, the Filter on its own does return True and False for the
> appropriate values.
>
> PS Alias:\> 1,2,3,4,5,6 | OnlyEven
> False
> True
> False
> True
> False
> True
> PS Alias:\>
>
> What very simple thing am I missing? Why aren't the objects discarded
> by where-object when I use the Filter name inside the script block?
>
> It's a niggle rather than a problem since I can just write any
> necessary code in the script block and bypass filters altogether.
>
> FWIW the example in about_filter.help.txt doesn't work for me either.
>
> Waiting for someone to explain the "Doh!" moment to me. 
>
> Thanks
>
> Andrew Watt MVP