Reputation: 328
If I have a Powershell script accessible through HTTP, how can I download it and execute it on the fly like what we can do in the bash?
curl --user user:pass https://fake.url | bash
Upvotes: 1
Views: 1173
Reputation: 550
Try
curl --user user:pass https://fake.url | powershell -Command -
If the value of Command is "-", the command text is read from standard input.
Upvotes: 1
Reputation: 354566
curl | bash
, or even worse, curl | sudo bash
is.In most cases you can probably use WebClient.DownloadString
and pass it to Invoke-Expression
: Invoke-Expression (New-Object Net.WebClient).DownloadString(«url»)
. I'm not sure whether that still opens a script:
scope for variables, though, so if that scope is used in the script it might not work. In that case you can download it as a file and execute the script. Then you also have to take care of the execution policy, though.
Upvotes: 2