Skip to content
OnMSFT.com
  • Home
  • About
  • Contact
  • Windows
  • Surface
  • Xbox
  • How-To
  • OnPodcast
  • Edge
  • Teams
  • Gaming
Menu
  • Home
  • About
  • Contact
  • Windows
  • Surface
  • Xbox
  • How-To
  • OnPodcast
  • Edge
  • Teams
  • Gaming
  1. Home
  2. How-to
  3. How to easily download a file with PowerShell – onmsft.com

How to easily download a file with PowerShell – onmsft.com

kip@onmsft.com kip@onmsft.com
November 18, 2022
2 min read

PowerShell is a handy, free task automation tool provided by Microsoft that lets you manage and, as you might’ve guessed from its name, automate your tasks on Windows with ease. However, that’s not all, though.

You can, for instance, also download internet files thanks to your PowerShell app. In this piece, we dive into the most straightforward method to get files with PowerShell. Here’s how you can get started.

How to download a file with PowerShell

One of the most common ways to download your file with PowerShell is by using the URL of the file you’d like to download. That’s precisely what we’ll be covering in this short guide. To complete your download, you’ll be using the Invoke-WebRequest cmdlet.

Also, before we head to the actual download, we’d also want to specify that you’ll need a specific destination where you can store the downloaded file. You’ll have to add a particular parameter to your cmdlet file.

Here’s what the complete syntax will look like:

Invoke-WebRequest -Uri <source> -OutFile <destination>

Depending on where you’d like to download the files from and the place you’d like to put your files, replace the source and destination variable with the URL of the file you’d like to download and the place you’d like to download it to.

After you’ve launched the PowerShell, type in the following dummy command. This is what it will look like:

# Source file location
$source = 'https://www.majorgeeks.com/files/details/4diskclean_free.html/4dskcln.exe'
# Destination to save the file
$destination = 'C:\programfiles
ewfolder'
#Download the file
Invoke-WebRequest -Uri $source -OutFile $destination

Here, the command downloads the file source from ‘https://www.majorgeeks.com/files/details/4diskclean_free.html/4dskcln.exe’, and then saves it to ‘c:\programfiles
ewfolder’
.

This should download the required files fairly simply. However, in some cases, you might get asked for login access before you can proceed with the download. You can do that by adding the -Credential parameter. Just add the following command to your code:

$credential = Get-Credential

Here’s what the complete command will look like now:

$credential = Get-Credential
$source = 'https://www.majorgeeks.com/files/details/4diskclean_free.html/4dskcln.exe'
$destination = 'C:\programfiles
ewfolder'
Invoke-WebRequest -Uri $source -OutFile $destination -Credential $credential

That’s it. Your download will begin.

Downloading a file with PowerShell without any hassles

Downloading files with PowerShell doesn’t have to be super complicated. With the method we’ve explained above, we believe it was a breeze for you. However, don’t hit the brakes just now. PowerShell packs tons of commands that can help you do just about anything on your PC. So, don’t stop just now; keep exploring things out there.

Share This Post:

Share this article:
Tags:
PowerShell Windows 10 Windows 11 How To
Previous Article Here’s what’s announced as coming to Microsoft 365 this week – onmsft.com Next Article Soccer Celebration comes to Minecraft – onmsft.com

Related Articles

How to Fix the Phone Link App Not Working on Windows 11 – onmsft.com

December 29, 2022

5 easy ways to make desktop shortcuts on Windows 11 – onmsft.com

December 29, 2022

How to customize precision touchpads on Windows – onmsft.com

December 22, 2022

Leave a Comment Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Chrome tests Gemini Live voice assistant in a floating overlay panel
  • Chrome’s Organizer feature may sync Gemini and AI conversations across devices
  • After Chrome, Edge tests launching the browser automatically when you sign into Windows
  • iPhone Fold Latest Rumors: Display, Cameras, RAM and Price Details Revealed
  • Samsung fears first mobile operating loss due to memory price surge

Recent Comments

No comments to show.
OnMSFT.com

OnMSFT.com covers Microsoft news, reviews, and how-to guides. Formerly known as WinBeta, we have been your source for Microsoft news since 1998.

Categories

  • Windows
  • Surface
  • Xbox
  • How-To
  • OnPodcast
  • Gaming
  • Edge
  • Teams

Recent Posts

  • Chrome tests Gemini Live voice assistant in a floating overlay panel
  • Chrome’s Organizer feature may sync Gemini and AI conversations across devices
  • After Chrome, Edge tests launching the browser automatically when you sign into Windows
  • iPhone Fold Latest Rumors: Display, Cameras, RAM and Price Details Revealed
  • Samsung fears first mobile operating loss due to memory price surge

Quick Links

  • About OnMSFT.com
  • Contact OnMSFT
  • Join Our Team
  • Privacy Policy
© 2010–2026 OnMSFT.com LLC. All rights reserved.
About OnMSFT.comContact OnMSFTPrivacy Policy