The “wget” cmdlet is Linux base tool that downloads the files using the provided URL within the terminal. It supports all types of protocols, including “FTP”, “FTPS”, “HTTP”, and “HTTPS”. Unfortunately, this cmdlet is not supported in PowerShell. However, PowerShell has other alternatives, including the “Invoke-WebRequest”, “Start-BitsTransfer”, or “Invoke-RestMethod” cmdlet. All these cmdlets are capable of performing operations that “wget” can.
This tutorial will overview a guide to finding the alternative to the “wget” cmdlet.
How to Download a File in PowerShell?
These approaches can be considered as a substitute for the “wget” cmdlet:
Method 1: Use the “Invoke-WebRequest” Cmdlet to Download a File
The cmdlet “Invoke-WebRequest” grabs the files from the internet by utilizing their URLs. It is the substitute for the “wget” cmdlet of Linux.
Example
This example will download a file from the internet using PowerShell:
$strg = "C:\Doc\File.pdf"
Invoke-WebRequest -URI $src -OutFile $strg
According to the above code:
- Initialize a variable “$src” and assign a URL of the file to download within inverted commas.
- After that, initiate another variable, “$strg” and assign a target file path within inverted commas.
- Add the “Invoke-WebRequest” cmdlet, specify a “-URI” (not -URL) parameter, and assign the “$src”.
- Lastly, add “-OutFile” option and assign the “$strg” variable.
Method 2: Use the “Invoke-RestMethod” Cmdlet to Download a File
The cmdlet “Invoke-RestMethod” is another alternative for the “wget” cmdlet. It also downloads the files from the internet using the provided URL.
Example
This demonstration will download a file from the internet using the provided URL:
$strg = "C:\Doc\File.pdf"
Invoke-RestMethod -URI $src -OutFile $strg
This is how the file is downloaded with PowerShell using the above code.
Method 3: Use the “Start-BitsTransfer” Cmdlet to Download a File
The “Start-BitsTransfer” cmdlet is a bit like the above-mentioned cmdlets with minor parameter differences.
Example
This example will demonstrate to download a file from the internet using the “Start-BitsTransfer”:
$strg = "C:\Doc\File.pdf"
Start-BitsTransfer -Source $src -Destination $strg
Instead of using the “-URI” use “-Source” parameter, and as an alternative of “-OutFile”, utilize the “-Destination” option:
That was all about downloading files from the internet.
Conclusion
The “wget” is a Linux-based cmdlet that aids the terminal to download files from the internet using its URL. It is not supported in PowerShell. However, PowerShell has several substitutes, including “Start-BitsTransfer”, “Invoke-RestMethod”, and “Invoke-WebRequest” cmdlets. This blog has elaborated on the “wget” cmdlet and its substitutes in PowerShell.