Comparing Invoke-WebRequest, WebClient, and Curl Methods for Windows Package Downloads
Introduction
Downloading files, such as winget cli from Github, is a common task for IT professionals and enthusiasts. With various tools available on Windows, such as PowerShell’s Invoke-WebRequest, WebClient, and curl (in both PowerShell and Command Prompt), you have multiple options to automate and streamline downloads. This post will guide you through each method, highlighting their usage, nuances, and differences.
Quick Links
- Prerequisites
- Method 1: Using Invoke-WebRequest in PowerShell
- Method 2: Using WebClient in PowerShell
- Method 3: Using Curl in PowerShell
- Method 4: Using Curl in Command Prompt
- PowerShell Curl vs. Command Prompt Curl
Prerequisites
- Windows 10 or later (with PowerShell and curl available by default)
- URL to the file you want to download such as https://github.com/microsoft/winget-cli/releases/download/v1.10.390/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
- Administrative privileges (recommended for installation tasks)
Method 1: Using Invoke-WebRequest in PowerShell
PowerShell’s Invoke-WebRequest cmdlet is a powerful and straightforward way to download files.
- Open PowerShell as Administrator.
- Use the following command:
Invoke-WebRequest -Uri "https://github.com/microsoft/winget-cli/releases/download/v1.10.390/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -OutFile "C:\tmp\winget_cli_installer.msixbundle"- Replace the URL with the actual download link and the path with your desired location. This command fetches the file from the specified URL and saves it locally. Invoke-WebRequest is ideal for scripting and automation, supporting authentication, headers, and more.
Method 2: Using WebClient in PowerShell
The WebClient class provides another way to download files in PowerShell, useful for compatibility with older scripts or when you need more granular control over the download process.
- Open PowerShell.
- Run the following commands:
$webClient = New-Object System.Net.WebClient$wc.DownloadFile("https://github.com/microsoft/winget-cli/releases/download/v1.10.390/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle", "C:\tmp\winget_cli_install.msixbundle")- Again, adjust the URL and output path as needed. WebClient is lightweight and works well for simple downloads, but lacks some of the advanced features of Invoke-WebRequest.
Method 3: Using Curl in PowerShell
Windows ships with curl as a built-in command-line tool. You can use it directly in PowerShell, though it behaves slightly differently compared to Linux or macOS environments.
- Open PowerShell.
- Run:
curl.exe -o "C:\tmp\winget_cli_install.msixbundle" "https://github.com/microsoft/winget-cli/releases/download/v1.10.390/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" - Note: Use curl.exe instead of just curl to avoid confusion with the PowerShell alias for Invoke-WebRequest. curl.exe provides robust options for downloads, including resume support, progress bars, and more.
Method 4: Using Curl in Command Prompt
You can also use curl in the classic Command Prompt (cmd.exe).
- Open Command Prompt.
- Type:
curl -o "C:\winget_cli_install.msixbundle" "https://github.com/microsoft/winget-cli/releases/download/v1.10.390/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"In Command Prompt, curl always refers to the executable and does not have conflicting aliases, making it straightforward to use.
PowerShell Curl vs. Command Prompt Curl
Powershell curl is actually an alias for Invoke-WebRequest meaning you would have to change the command to what the Invoke-WebRequest expects.
So instead of
curl -o "C:\tmp\winget_cli_install.msixbundle" "https://github.com/microsoft/winget-cli/releases/download/v1.10.390/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle",
your command would be
Invoke-WebRequest -Uri "https://github.com/microsoft/winget-cli/releases/download/v1.10.390/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -OutFile "C:\tmp\winget_cli_installer.msixbundle"
Conclusion
Whether you’re scripting downloads for automation or manually fetching packages, Windows offers several flexible methods. For PowerShell users, Invoke-WebRequest and WebClient offer native options, while curl.exe brings cross-platform consistency. In Command Prompt, curl is straightforward with no alias conflicts. Always ensure you use the correct command for your environment to avoid confusion and get the most out of your download operations.
While any method will download the file, Invoke-WebRequest feels like it takes longer to download that using WebClient or CURL to me.
References & Further Reading
Don’t forget to bookmark and check back for updates. Community Engagement: Join the conversation on discord