2

Currently I have the following code below, which does not work for me. I would Like it to behave like this

some-output-from-some-function | FILTER_DATA

or

some-output-from-some-function | FILTER_DATA | Filter_01

With the function below (without the $id included) i need to catch the some-output-from-some-function int ovariable and execute it like this (which does NOT suit me):

$a = some-output-from-some-function
"$a" | FILTER_DATA

Please help. I want it to be universal, not specific to one or two passed arguments ...

Function FILTER_DATA ($id){
                      [CmdletBinding()]
                      Param(
                            [Parameter(ValueFromPipeline)]
                            $item
                           )
       $item | % {$PSItem.replace("&lt;","<").replace("&gt;",">")} |
               % {$PSItem -replace "<table>", "$description<table class=sortable id=$id" `
                          -replace "</table>","</table></span>" `
}}
1
  • It would be nice to see the error you have. Commented Feb 12, 2019 at 8:36

1 Answer 1

1

Param() can't be used if the arguments are passed in function declaration. In your case you passed $ID while declaring function. You can use below code which should work fine.

Function FILTER_DATA {
                      [CmdletBinding()]
                      Param(
                            [Parameter(ValueFromPipeline)]$item,
                            $ID
                            )
       $item | % {$PSItem.replace("&lt;","<").replace("&gt;",">")} |
               % {$PSItem -replace "<table>", "$description<table class=sortable id=$id" `
                          -replace "</table>","</table></span>" `}
}

And now FILTER_DATA can accept input $Item from pipeline.

Sign up to request clarification or add additional context in comments.

2 Comments

hmmm, what about passing output of this custom function, to Another custom function … like: "$a"|FILTER_DATA|Filter_01
You need to configure Filter_01 to accept ValueFromPipeline and it should work. You need to return value from FILTER_DATA function which can be piped to Filter_01 function. In your FILTER_DATA function, it's not returning anything, so Filter_01 doesn't have any input.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.