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?
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
Automatic download and start remote
PowerShell script w/0 save (on the fly):
iex (iwr $ScriptURL).Content
WTF:
alias iex,iwr
More help:
Get-Help Invoke-Expression
Get-Help Invoke-WebRequest
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With