Skip to content

Instantly share code, notes, and snippets.

@LawrenceHwang
Created July 14, 2016 05:54
Show Gist options
  • Save LawrenceHwang/ae5abf640097ed087937499b6e7d7d6e to your computer and use it in GitHub Desktop.
Save LawrenceHwang/ae5abf640097ed087937499b6e7d7d6e to your computer and use it in GitHub Desktop.
# Source: https://blogs.msdn.microsoft.com/mssmallbiz/2016/07/10/how-to-download-all-of-the-free-ebooks-and-resources-in-my-free-ebooks-giveaway/
# Source: http://www.mssmallbiz.com/ericligman/Key_Shorts/MSFTFreeEbooks.txt
# Script for convenience. No proper error handling whatsoever. Saves to user's download\FreeEbook folder.
# Parsing the http links
$LinkSource = 'http://www.mssmallbiz.com/ericligman/Key_Shorts/MSFTFreeEbooks.txt'
$link = ((Invoke-WebRequest -Uri $LinkSource).content -split "`n" | where {$_ -like 'http://*'}).trim()
$path = '~\Downloads\FreeEBook'
if (!(test-path -Path $path)){
mkdir $path | Out-Null
}
foreach ($l in $link){
$url = "$l"
$response = [System.Net.WebRequest]::Create($url).GetResponse()
$file = ($response.ResponseUri.OriginalString -split "/")[-1]
$response.Close()
Invoke-WebRequest -Uri $url -outfile "$path\$file"
$response = ''
$file = ''
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment