To download a file using PowerShell in the command line, you can use the Invoke-WebRequest cmdlet. Here's a basic example of how to do it:
Invoke-WebRequest -Uri "http://example.com/file.txt" -OutFile "C:\path\to\save\file.txt"
In this command:
-Uri specifies the URL of the file you want to download.
-OutFile specifies the path where you want to save the downloaded file.
You can also use the alias wget or curl (available in PowerShell 3 and later, though curl is an alias for Invoke-WebRequest and doesn't support all curl parameters) for a more concise syntax, similar to how you would use wget or curl in Linux or macOS terminal:
wget "http://example.com/file.txt" -OutFile "C:\path\to\save\file.txt"
or
curl "http://example.com/file.txt" -OutFile "C:\path\to\save\file.txt"
However, keep in mind that while wget is a proper alias for Invoke-WebRequest in PowerShell, using curl might not work exactly as you're used to if you're coming from a Unix-like environment, due to differences in supported parameters.
For a more straightforward and native PowerShell experience, using Invoke-WebRequest directly is recommended.
Example with Progress Bar
By default, Invoke-WebRequest shows a progress bar. If you want to disable it, you can use the -DisableProgress parameter (available in PowerShell 6 and later):
Invoke-WebRequest -Uri "http://example.com/file.txt" -OutFile "C:\path\to\save\file.txt" -DisableProgress
Using .NET for Downloading
Alternatively, you can use the System.Net.WebClient .NET class directly in PowerShell for downloading files. This method is useful, especially in environments where you might not have the latest PowerShell version:
$wc = New-Object System.Net.WebClient
$wc.DownloadFile("http://example.com/file.txt", "C:\path\to\save\file.txt")
Or, more concisely:
(New-Object System.Net.WebClient).DownloadFile("http://example.com/file.txt", "C:\path\to\save\file.txt")
These methods provide a straightforward way to download files using PowerShell.