Downloading files with PowerShell using the BitsTransfer module

@sstranger told me on Twitter that you can also use the BitsTransfer module, to download files via PowerShell (previous post).

He wrote a script to download several files from the microsoft website.

Here is a modified version of his script, using test files with size 50MB and 100MB:

# path to store the data
$global:path = "c:\TEMP\"

# loads the BitsTransfer Module
Import-Module BitsTransfer
Write-Host "BitsTransfer Module is loaded"

# test data from http://www.thinkbroadband.com/download.html
$fileLinks = @("http://download.thinkbroadband.com/50MB.zip",
 "http://download.thinkbroadband.com/100MB.zip");

# start the download
Foreach ($fileLink in $fileLinks)
{
 Start-BitsTransfer $fileLink $path
}
Write-Host "Files are downloaded to $path"

Save this script as PowerShellFileDownloader.ps1 and run it in the Windows PowerShell ISE (which is included by default in Windows 7).

If you can’t run the script due to security reasons, change your execution policy:
(read more about running PowerShell scripts here)

Set-ExecutionPolicy RemoteSigned

Warning: changing the ExecutionPolicy might cause a security risk.

Some screenshots of the script running with the BitsTranfser module:

Have fun! ;)

About these ads

2 thoughts on “Downloading files with PowerShell using the BitsTransfer module

  1. there is a powershell script for it:
    http://huddledmasses.org/wget-2-for-powershell/
    http://huddledmasses.org/wget-for-powershell/
    but I didn’t test it.

    My post didn’t had the intention to create a wget replacement. I was just busy writing a ps test script to download some files and a user on twitter told me that this BitsTransfer is more useful so I tested it out in my ps script.

    I have tested some wget implementation for windows but it is a bit bumby and slompy to use :( (hey I just invented two words :p)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s