Skip to main content

This script can be used to define a file parameter path on a website and a "save" location in the script, when run the script will download the specified file to the set location.The script may be amended and used for any other purpose.

# Script:   Download Anything.ps1
# Purpose:  Downloads a file from the web to the specified file path.
# Author:   Paperclips
# Email:    pwd9000@hotmail.co.uk
# Date:     Nov 2011
# Notes:
# -Get-URL http://website.com/downloads/Iwantthisfile.txt thisfile.txt
# -Get-URL http://website.com/downloads/Iwantthisfile.txt C:\myfolder\thisfile.txt

$url = "http://website.com/downloads/Iwantthisfile.txt"
$path = "C:\temp\thisisthefile.txt"
# param([string]$url, [string]$path)

if (!(Split-Path -parent $path) -or !(Test-Path -pathType Container (Split-Path -parent $path)))
{
    $path = Join-Path $pwd (Split-Path -leaf $path)
}

"Downloading [$url]`nSaving at [$path]"
$client = new-object System.Net.WebClient
$client.DownloadFile($url, $path)
#$client.DownloadData($url, $path)

$path