Site icon Kommands.com

How to Download Files through PowerShell

Overview

Downloading files via the internet is a routine chore in today’s digital age. However, manually downloading files can take a while, especially if you need to download a lot of files at once. This task can be automated with the help of PowerShell, a strong tool, helping it go more quickly and effectively. This article will go through two distinct approaches to downloading things from the web using PowerShell.

A quick and effective technique to automate the process is by utilizing PowerShell to download things from the internet. PowerShell has two techniques that can be used to complete this task, whether you need to download a single file or a number of files. by becoming aware of the System. You may automate your downloads and save time by using the Invoke-WebRequest cmdlet and the Net.WebClient object.

Method 1: Download from the Web using the System.Net.WebClient Object

Utilizing the System is part of the first strategy. To download files from the internet, use the Net.WebClient object. The System is created using the following code. To download a file from the internet, one utilizes a Net.WebClient object and the DownloadFile method:

$WebClient = New-Object System.Net.WebClient $WebClient.DownloadFile("https://drive.google.com/FILE URL=download","C:\TestFolder444\TestFile444.zip")

In this code, the URL of the file to be downloaded is specified in the DownloadFile method, and the destination folder is specified in the second parameter.

Method 2: Download using Invoke-WebRequest

The second method uses the Invoke-WebRequest cmdlet to download files from the web. The following code sets the source URL and destination folder and then downloads the file using Invoke-WebRequest:

$source = 'https://URL' 
$destination = 'c:\TESTFolder444\TEST444.zip'

Invoke-WebRequest -Uri $source -OutFile '$destination'

In this code, the source URL is specified in the $source variable, and the destination folder is specified in the $destination variable. The Invoke-WebRequest cmdlet is used to download the file, and the OutFile parameter is used to specify the destination folder.

Exit mobile version