Windows – how can I download web pages from the command line in windows

batchbatch-filehttpwgetwindows

Well, I'm trying to do some automation using batch file to speed up my daily routine at work, and I need to solve these little questions:

  1. I want to install wget command, but using only the pure Windows Command Prompt
  2. I want to download some things stored http server online
  3. These "things" need to be downloaded and placed in the same folder that my batch file resides
  4. I want these things to be executed and my batch file to be deleted
  5. Need to perform all operations without "asking permission" of administrator

Please, can you guys do that for me? Or maybe give some help with the first steps?

Best Answer

This answer depends on having PowerShell 3.0 to use the Invoke-WebRequest cmdlet instead of wget. It can be downloaded from here

You could achieve this without creating a file to run this from in the first place. I imagine you're remotely triggering this task somehow, in which case you can do the following:

powershell.exe -Command "& {Invoke-WebRequest http://google.com -OutFile C:\Path\To\File\out.html}"

This way, you leave no trace of a batch file, and you can pick the location where you would like your file to be placed.

To verify the PowerShell version installed is suitable before running the command, wrap it in an if statement like so:

powershell.exe -Command "& {if($PSversionTable.PSVersion.Major -ge 3) {Invoke-WebRequest http://google.com -OutFile C:\Path\To\File\out.html}}"