Say I only want to pipe my output to another function depending on the value of a variable, is there some way to do this in powershell?
Example :
if ($variable -eq "value"){$output | AnotherFunction}
else {$output}
@mjolinor's example is how I am doing it now, just curious if there is a better way to do it.
You can use an If clause:
if ($variable -eq "value"){$output | AnotherFunction}
else {$output}
Example implemented as a fiter:
filter myfilter{
if ($variable -eq "value"){$_ | AnotherFunction}
else {$_}
}
Then:
$variable = <some value>
get-something | myfilter
You may get the results you are looking for by piping to the Where-Object.
Example:
My-Command | Where-Object {$variable -eq "value"} | AnotherFunction
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With