How to execute the output of a command inside a scriptblock tag?

22 Views Asked by At

THIS IS JUST A PROOF OF CONCEPT

I have the following code I wrote that will store the description of a module in a variable and then execute it:

$p = Find-Module tpl | select -ExpandProperty 'Description';& ([scriptblock]::Create($p))

the description is an echo command: echo "this is a proof of concept"

I have shortened it a little using aliases:

$p = Fimo tpl | select -Exp 'Des*';& ([scriptblock]::Create($p))

I believe it can be shortened even further using something like:

Icm -ScriptBlock {Fimo tpl|select -Exp 'Des*'}

but this just returns the whole output: echo "this is a proof of concept"

instead of executing it.

How can I get it to execute the command inside the scriptblock tag?

0

There are 0 best solutions below