Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to pass a variable into a piped powershell script?

I'm basing a small project off of the below one-liner, but I'm struggling to pass parameters into it on the same line.

irm get.scoop.sh | iex

This script can take additional parameters, such as -ScoopDir.

How does one pass -ScoopDir C:\foo\bar into the one-liner?

like image 994
tresf Avatar asked Dec 06 '25 20:12

tresf


1 Answers

It can't be done with Invoke-Expression, however you can do it by converting the expression into a script block first then you can pass arguments as if it was a function.

Do note:

iex

This still applies for the [scriptblock]::Create(...) approach.

& ([scriptblock]::Create((irm get.scoop.sh))) -ScoopDir C:\foo\bar
like image 101
Santiago Squarzon Avatar answered Dec 08 '25 15:12

Santiago Squarzon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!