1

I have a PowerShell script statically hosted on my website and I want to run it on my machine without manually downloading it. So I do this:

iwr https://mywebsite/test.ps1 | iex

Which works perfectly until you don't need to pass any arguments. But if I need to use arguments what options do I have?

As a workaround I can use variables instead of arguments like so:

$arg=$true; iwr https://mywebsite/test.ps1 | iex

but this is not ideal.

Is there any better way to do this?

1 Answer 1

4

Create a ScriptBlock from the script file and execute that:

& ([scriptblock]::Create((iwr https://mywebsite/test.ps1))) -param1 123 -param2 "Hello there"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.