0

I am one of the few that decided to learn powershell instead of bash. I'd like to learn how to do the same thing as wget, for powershell. How to I do the following commands in powershell.

wget -r --no-parent http://curric.rithmschool.com/springboard/exercises/
wget -r --no-parent http://curric.rithmschool.com/springboard/slides/
wget -r --no-parent http://curric.rithmschool.com/springboard/lectures/
5
  • the most obvious is to install the windows version of wget and call that from inside PoSh. [grin] ///// for pure powershell, take a look at Invoke-RestMethod. the ps7+ version of that cmdlet is supposed to be quite a bit better than the ps5.1 version.
    – Lee_Dailey
    Commented Jan 30, 2021 at 0:31
  • To be clear, this is not a difference bash vs posh but Unix vs Windows. wget is a program, not part of bash. Most Unix systems come with wget, and you can run it from any shell or even without a shell. Windows systems don't come with wget, and even if you install bash on Windows (you can) that doesn't give you wget; OTOH if you install wget you can run it from anywhere. Of course some things, notably WSL, provide a whole range of tools, typically including both bash and wget. Commented Jan 30, 2021 at 3:33
  • alternatively you could install powershell on linux, :)
    – Jasen
    Commented Jan 30, 2021 at 3:39
  • So, this is a webpage of links to other webpages. I was told it was a file. So it seems this command was trying to download the page for offline use... Not sure if this is helpful. I appreciate everyone's fast responses. Commented Jan 30, 2021 at 3:48
  • 3 ways to download files with PowerShell
    – postanote
    Commented Jan 30, 2021 at 4:44

1 Answer 1

1

See here for 4 ways to interact with a webserver depending on the nature of the service you are accessing and the way you want to access them: https://adamtheautomator.com/powershell-download-file/

I'd recommend the System.Net.WebClient approach if you just want to download a file, but there are variants for API calls and other protocols like BITS.

This is is a call I saw in a script I was working with earlier today that will just download a file (a CI/CD agent for azure):

$WebClient=New-Object Net.WebClient; 
$Uri='https://vstsagentpackage.azureedge.net/agent/2.181.1/vsts-agent-win-x64-2.181.1.zip';
$WebClient.DownloadFile($Uri, "c:\path\to\download\to\agent.zip");
2
  • 1
    Get-WebRequest and Invoke-WebRequest too. Commented Jan 30, 2021 at 1:01
  • 1
    But wget -r doesn't download ONE page; it follows references and links and automatically downloads ALL accessible URLs, or at least MANY depeding on the other arguments like --no-parent in this Q. That's the difficult part. Commented Jan 30, 2021 at 3:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .