How to download a file on Windows Core

January 10, 2018
Cover Image

Windows Core is great.  Smaller disk footprint.  Less memory usage.  Boots up super-fast.  But with these benefits comes some caveats -- for example, no web browser.

So then when you need to download a file or download an installer, how do you do it?  The answer is...POWERSHELL TO THE RESCUE!!!

Here's a PowerShell script to download a URL to a local file.

[CmdletBinding()]
param(
 [Parameter(Mandatory=$true, HelpMessage='URL of to download')]
 [ValidateNotNullOrEmpty()]
 [string]
 $url,
 [Parameter(Mandatory=$true, HelpMessage='Save to filename')]
 [ValidateNotNullOrEmpty()]
 [string]
 $saveAsFilename)

$toFilename = "$PSScriptRoot\$saveAsFilename"

Write-Output "Downloading '$url' to '$toFilename'..."

Invoke-WebRequest -uri $url -outfile $toFilename

Write-Output "Downloaded."

Save this file to your Windows Core machine and rename it to end with *.ps1.

It takes two args: -url and -saveAsFilename.  The 'url' arg is the url to the file that you want to download.  FYI, it doesn't follow HTTP redirects so you'll need to get the exact url to download.  The 'saveAsFilename' arg is the name of the file that will be written to disk.

Here's the link to that script again.

I hope this helps.

-Ben