Skip to content

Download files from the Windows command line

Original command-line illustration (external source; unavailable during this update’s check).

For ordinary downloads on Windows, use a maintained download tool or PowerShell’s web cmdlet. The URL below is an illustrative placeholder, not a verified download endpoint. Replace it with a trusted HTTPS address you are authorized to access, and choose a writable destination that will not overwrite a file you need. These examples save a file; they do not run it. None was executed for this update.

1. curl.exe

First check whether curl is available:

curl.exe --version

The official curl Windows page provides current builds and verification files if you need a separately maintained copy. It also notes that Microsoft ships curl with Windows 10 and 11. Use curl.exe rather than the ambiguous curl alias in Windows PowerShell.

curl.exe --fail --location --proto "=https" --proto-redir "=https" --output log.csv "https://example.com/reports/log.csv"

This example follows redirects but restricts transfers and redirects to HTTPS. It requests failure on HTTP error responses and writes to log.csv. Consult the curl manual for these options. Keep certificate verification enabled; HTTPS alone does not establish that a downloaded file is trustworthy.

2. Invoke-WebRequest

The original heading “PowerShell 1” was ambiguous: Invoke-WebRequest was introduced in Windows PowerShell 3.0, not version 1. For Windows PowerShell 5.1, include -UseBasicParsing to avoid the script-execution risk of parsing web-page content, as explained in Microsoft’s documentation:

Invoke-WebRequest -UseBasicParsing -Uri "https://example.com/reports/log.csv" -MaximumRedirection 0 -OutFile log.csv

This example deliberately refuses automatic redirects. If the server redirects, obtain and verify the final HTTPS URL instead of blindly following it. A failed transfer may leave an incomplete file; check the command result before using the output.

3. BITS, where the module is available

On Windows systems with the BitsTransfer module, Start-BitsTransfer is another option. This is a method number, not a promise that the module is available in every PowerShell version or environment:

Start-BitsTransfer -Source "https://example.com/reports/log.csv" -Destination log.csv

What changed from the older examples?

  • certutil: The original used a certificate-management tool as a downloader. Microsoft documents certutil and its URL-cache operation; this guide no longer recommends repurposing it for general downloads.
  • wget: The old direct link pointed to a Wget 1.11.4 installer over unencrypted HTTP. Do not use that installer recommendation. If Wget is specifically required, consult the official GNU distribution information and your approved software source rather than that old binary. No third-party Windows installer is endorsed here.
  • WebClient: The old System.Net.WebClient.DownloadFile example is legacy .NET code. Microsoft deprecated WebClient starting with .NET 6. It can still exist in older environments, but is not the preferred pattern for new code.

Starting PowerShell from a command prompt

The original forms select Windows PowerShell:

powershell -command "..."

or:

powershell -file file.ps1

Modern PowerShell uses pwsh instead, as described in Microsoft’s executable-name guidance. The ellipsis is a placeholder, not a runnable download command. Run a script file only after checking its contents and source; do not disable execution policy or other security controls just to run a download example.

Post a Comment

Previous Post Next Post