Windows Server

It’s not wget or curl, it’s iwr in Windows

Powershell comes with a handy little cmdlet to download files from the internet called Invoke-WebRequest which is documented at https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.2. There’s an alias for it so it can be called as just iwr. Let’s say there’s a file at https://pathtothefile/myfile.txt and we want to download it to the working directory as simply myfile.txt. That could be done with the following command:

iwr -uri https://pathtothefile/myfile.txt -OutFile ./myfile.txt -UseBasicParsing -UseDefaultCredentials

In the above example, we used the -uri to identify the target resource and -OutFile to list the local location. The above command used basic parsing as we were accessing a resource from an older server, although that wouldn’t be required for newer servers. The file we were accessing was on a Windows server in the domain that required authentication, so we used the default credentials. A file on a public site being accessed from a newer server likely wouldn’t require either of those flags.

iwr also comes with support for much of what we’d send to a curl as quoted header information and specific handlers to communicate with endpoints. For example, the user agent we’re using can be sent with a -UserAgent or we could send session variables with -SessionVariable. Or we could include a dictionary of header information with a -Headers option. There are also options for standard token handling, session management, and in the case of a POST, PATCH, or DEL, we can also supply a body with, and this will come as a surprise, -Body.