powershell - How to pass custom filter function to Where-Object -


For the past few hours I am trying to figure out how a script block can be filtered for the function Is the object. I have not received any documents, I should remember something. I looked at "filter script" and "function: script" definitions, but I do not know how it is used and I can not find it anywhere.

  function test {the ultimate ($ f, $) $ x = $ what? Where $ f $ x} $ mywhat = @ ('aaa,' b ',' abb ',' bac ') Filter Script: myfilter {$ _- like' a * '} Test- $ mywhat -xx $ myfilter < / Code>  

Can someone point me in the right direction?

It is not clear what you are asking here.

A filter is a function and not a script block where the object takes the script as the input if you want to specify the position inside a function using parameters , Then you can use script block-parameter.

  function test {param ([scriptblock] $ f, $ what) $ x = $ what | Where $ f $ x} $ myfilter = {$ _- like 'a *'} test- what $ mywhat -f $ myfilter # or combine them- what $ mywhat -f {$ _- like 'a *'} < / Code>  

If you want to use only one filter, then how to do it:

  Filter script: myfilter {if ($ _-like 'a * ') {$ _}} $ Mywhat | Myfilter   

this $ mywhat | Will be equal to {$ _-like 'a *'}

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -