Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl http://url/script.ps1 | powershell possible?

I just want to replicate the same behavior that I do on Linux systems

c:\> \{CURL_EQUIVALENT_ON_WINDOWS} - http://url/script | powershell 

Is that possible?

Basically I want to execute a stream I download from a server.

IE: in steps:

1) Find out how to execute streams in a powershell. Execute a stream (that I already have on the file system)

c:\> type script.ps1 | powershell -command - 

but this doesn't work.

There is an option -File to execute a "File", and basically I want to execute the stream if possible.

2) Find out how to execute a stream I download from the server and pipe it in to a powershell.

like image 993
p4tux Avatar asked Apr 23 '13 16:04

p4tux


People also ask

Can I use curl with PowerShell?

curl requires minimal user interaction and is therefore preferred for automation. curl in PowerShell uses Invoke-WebRequest . From PowerShell 3.0 and above, you can use Invoke-WebRequest , which is equivalent to curl .

How do I curl a URL in PowerShell?

The conclusion is that if you need to use the curl (as same as in the Windows command prompt) in PowerShell then you need to call the curl executable( curl.exe ) directly. Else, you should stick to the PowerShell curl alias which resolves to the Invoke-WebRequest cmdlet under the hood.

How do you curl a URL?

The syntax for the curl command is as follows: curl [options] [URL...] In its simplest form, when invoked without any option, curl displays the specified resource to the standard output. The command will print the source code of the example.com homepage in your terminal window.

Is invoke-WebRequest the same as curl?

In PowerShell, the cURL command is an alias of the Invoke-WebRequest cmdlet. The Invoke-WebRequest cmdlet is used to send requests to a website.


1 Answers

Thanks to dugas I learn how to execute streams with powershell, and with this link http://blog.commandlinekungfu.com/2009/11/episode-70-tangled-web.html I understand how to get content as a stream from http with powershell.

So the final curl | powershell pipe looks like this:

PS C:\>(New-Object System.Net.WebClient).DownloadString("http://url/script.ps1") | powershell -command -

Thanks a lot to everyone that contribute to this question :-)

like image 76
p4tux Avatar answered Sep 29 '22 12:09

p4tux