Created
July 14, 2016 05:54
-
-
Save LawrenceHwang/ae5abf640097ed087937499b6e7d7d6e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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