cURL for Powershell

OK, so the title of this post is a bit lot misleading. I haven’t implemented cURL in Powershell, but I did want a simple way to simply do an HTTP GET against a URL and download its contents. With cURL, it’s as simple as:

$ curl http://isitchristmas.com

Easy! This will download the URL as a string that can be piped into another command. In Powershell, it’s a bit more cumbersome:

PS > (New-Object net.webclient).DownloadString(
      'http://isitchristmas.com')

It will get the job done, but that’s a lot to remember just to get a string from an HTTP GET. I’ve added the following bit of code to my Powershell Profile to make this task a bit easier:

function Get-URL([string] $url){
  (New-Object net.webclient).DownloadString($url)
}
Set-Alias curl Get-URL

Those expecting the full functionality of cURL with the curl alias are going to be disappointed, but if you’re simply wanting to grab the contents of a URL, this will do the trick. Now I can get the contents of a website and pipe it into another command in Powershell, such as installing pip:

PS > curl https://raw.github.com/pypa/pip/master/contrib/get-pip.py | 
     python