Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run Powershell script from URL without temporary file

Tags:

powershell

I want to write a PowerShell script that runs a PowerShell script stored at a URL, passing both custom arguments and forwarding any arguments that are given to this PowerShell. Concretely, I can do:

$VAR=Invoke-WebRequest http://example.com/powershell.ps1
$TEMP=New-TemporaryFile
$FILE=$TEMP.FullName + ".ps1"
$VAR.Content | Out-File $FILE
& $FILE somearguments $args

I'd ideally like to do that without using a temporary file, however powershell -content - doesn't seem to allow also passing arguments. Is there any way to avoid the temporary file?

like image 503
Neil Mitchell Avatar asked May 10 '17 21:05

Neil Mitchell


2 Answers

Stolen straight from chocolatey's site. I use this more often than i should

iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

source

like image 79
Daniel Agans Avatar answered Oct 18 '22 06:10

Daniel Agans


Automatic download and start remote PowerShell script w/0 save (on the fly):

iex (iwr $ScriptURL).Content

WTF:

enter image description here

alias iex,iwr

More help:

Get-Help Invoke-Expression
Get-Help Invoke-WebRequest
like image 41
SynCap Avatar answered Oct 18 '22 06:10

SynCap