villasv
villasv

Reputation: 6831

Run PowerShell script from url passing parameters

Following PsGet example, this is how I run a ps1 from an url:

(new-object Net.WebClient).DownloadString($Url) | iex

Now, it would be great if I could pass parameters to that script in a one liner like this, but any parameters I pass go to iex instead of getting passed to the script.

How can it be done in a one line? Perhaps it can have two chained commands, but three commands is already too much for a one line.

Upvotes: 2

Views: 2475

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174485

You could create an unnamed scriptblock from the string and then invoke it using the call operator (&):

& $([scriptblock]::Create((New-Object Net.WebClient).DownloadString($Url))) -param1 argumentvalue

Upvotes: 6

Related Questions