wget for PowerShell

Posted: July 27, 2008 in Computer and Internet

So as it stands I very much like the utilities found in most unix systems. They are often too small and you have to yank them together to make anything useful out of it, sometimes this is great, sometimes not so great. But the wget utility is one of those very neat utilities. There are many ports for windows (e.g. gnuwin32 which by the way is a very useful package unless you are using cygwin/msys).

Either way I thought this would be very simple to accomplish through .Net, and it is

   1: $c = new-object System.Net.WebClient
   2: $c.DownloadFile("http://surfnet.dl.sourceforge.net/sourceforge/gnuwin32/wget-1.10.1.exe", "$pwd\wgetsetup.exe")
That’s it! Well almost, you don’t get any progress. I made a simple search and hit this
It tries to be a bit more clever about it all, however it didn’t work for the FTP protocol, so I fixed that. Change the line
if($res.StatusCode -eq 200) {
if($res.StatusCode -eq 200 -or $res.StatusCode -eq "OpeningData") {
So there you have it, a wget light without having to tax around an extra binary (although you will need to tax around the .Net framework instead :=)
PowerShell is just awesome, as a terminal it still has ways to go, but as a pipeline idea it is far superior and with the tight integration with .Net and the simplicity to grab .Net classes/objects (and vice versa, it is very simple to add scripting to a .Net application through powershell as it works through objects in the pipeline) it is a sure winner. There are now also incarnations where you can use powershell code in ASP pages instead of VB.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s