1

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?

mklement0
  • 382,024
  • 64
  • 607
  • 775
I am Jakoby
  • 577
  • 4
  • 19
  • 1
    `& ([scriptblock]::Create((Fimo tpl).Description))` ? – Santiago Squarzon Nov 21 '22 at 03:24
  • you will forever be a legend Santiago. just got a job as a junior pentester and have been experimenting with some weird concepts – I am Jakoby Nov 21 '22 at 03:26
  • 2
    `iex (Fimo tpl).Description` is shorter. and you're playing with fire here – Santiago Squarzon Nov 21 '22 at 03:26
  • 1
    im def aware. why im trying to bring this concept up – I am Jakoby Nov 21 '22 at 03:28
  • 1
    Leaving the code-golf aspect aside, all these commands should (mostly) exhibit the same behavior (the `iex` command runs directly in the caller's scope, not in a child scope the way the `& ...` commands do). If your `.Description` property truly contains a string with _verbatim_ value `echo "this is a proof of concept"`, all of these commands should work as intended - none would output `echo "this is a proof of concept"`, all would output verbatim `this is a proof of concept` – mklement0 Nov 21 '22 at 03:30
  • 1
    I think your question has been answered and has been answered before (see linked question) so I think it's safe to close it as a duplicate unless there is something we're missing – Santiago Squarzon Nov 21 '22 at 03:45

0 Answers0