I know I can download and install the aformentioned library (wget for Windows), but my question is this:

In Windows PowerShell, is there a native alternative to wget?

I need wget simply to retrieve a file from a given URL with HTTP GET. For instance:

wget http://www.google.com/
link|improve this question

feedback

3 Answers

up vote 22 down vote accepted

If you just need to retrieve a file, you can use the DownloadFile method of the WebClient object:

$client = new-object System.Net.WebClient
$client.DownloadFile( $url, $path )

Where $url is a string representing the file's URL, and $path representing the local path the file will be saved to.

Note that $path must include the file name; it can't just be a directory.

link|improve this answer
1  
So far this has been the best solution proposed. Also given that it seems I can rewrite it in one line format as (new-object System.Net.WebClient).DownloadFile( '$url, $path) it is the best correspondence for wget I have seen so far. Thanks! – jsalonen Nov 28 '11 at 10:49
feedback

It's a bit messy but there is this blog post which gives you instructions for downloading files.

Alternatively (and this is one I'd recommend) you can use BITS:

Import-Module BitsTransfer
Start-BitsTransfer -source "http://urlToDownload"

It will show progress and will download the file to the current directory.

link|improve this answer
1  
BITS relies on support at the server end, if available this works in the background and you can get progress updates with other cmdlets. – Richard Nov 28 '11 at 10:42
I tried to fetch google.com, but all I get is Start-BitsTransfer : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)). I'm puzzled :| – jsalonen Nov 28 '11 at 10:45
1  
@jsalonen I think that BITS will only download files rather than pages. As Richard says it relies on some server side support (although I don't think it's Microsoft specific). – Matthew Steeples Nov 28 '11 at 11:09
I see and I think I get the point in using BITS, however, its not what I'm looking for in here. – jsalonen Nov 28 '11 at 11:23
feedback

Not a native solution, but you can use PsUrl module from PsGet repository.

Do the following:

  • If you haven't done it yet, run Set-ExecutionPolicy RemoteSigned to allow installation of signed modules from remote sources (warning: make sure you understand the security implications)
  • Install PsGet module installer for PowerShell from http://psget.net/
  • Install PsUrl module: install-module PsUrl

Now, you can just use PsUrl like wget:

get-url http://example.com/

Just the way as wget would behave.

Note that you not only get wget to work, but you can also now easily install other modules from PsGet repository.

link|improve this answer
Thing is, a native method was requested. – Bob Mar 1 at 12:00
True, but I also asked the question in the first place. – jsalonen Mar 1 at 18:13
Sorry, I can't believe I missed that... – Bob Mar 1 at 22:19
Could the downvoter explain me, what is wrong with this answer? I would gladly like to improve on it. – jsalonen Mar 5 at 13:17
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.