http://ligman.me/29olaWI<\/a> via a web browser, the download starts.<\/p>","upvoteCount":1,"datePublished":"2017-07-17T18:08:41.000Z","url":"https://community.spiceworks.com/t/powershell-help-downloading-2016-ms-free-ebooks/593849/8","author":{"@type":"Person","name":"josephhays2","url":"https://community.spiceworks.com/u/josephhays2"}},{"@type":"Answer","text":"Does the path ‘D:\\Users\\johnh\\Desktop\\books2016’ exist? PowerShell usually doesn’t like implicitly creating directories. Testing the command with an non-existing destination directory produced the same error message for me.<\/p>","upvoteCount":1,"datePublished":"2017-07-17T18:16:45.000Z","url":"https://community.spiceworks.com/t/powershell-help-downloading-2016-ms-free-ebooks/593849/9","author":{"@type":"Person","name":"gungnir","url":"https://community.spiceworks.com/u/gungnir"}},{"@type":"Answer","text":"
$dest = \"D:\\Users\\johnh\\Desktop\\books2016\\\" \n$bookList = Get-Content \"D:\\Users\\johnh\\Desktop\\MSFTFreeEbooks.txt\"\n[string[]]$books = \"\" \n$books = $bookList.Split(\"`n\") \n$books = $books[1..($books.Length -1)] \n\n \n# Download the books \nforeach ($book in $books) {\n \n Try{\n $test = Invoke-WebRequest $book -Method Head -ErrorAction Stop\n $hdr = $test\n }catch{\n write-warning \"Unable to reach $book\"\n }\n $title = $hdr.BaseResponse.ResponseUri.Segments[-1]\n $title = [uri]::UnescapeDataString($title)\n $saveTo = $dest + $title\n Invoke-WebRequest $book -OutFile $saveTo\n\n} \nWrite-Output \"Downloaded $((get-childitem D:\\Users\\johnh\\Desktop\\books2016).count)/$($books.Count) books\"\n<\/code><\/pre>\nWARNING: Unable to reach http://ligman.me/29hV6ZM\nWARNING: Unable to reach http://ligman.me/29d1qAV\nWARNING: Unable to reach http://ligman.me/29pfpbI\nDownloaded 5/8 books\n<\/code><\/pre>\nhttp://ligman.me/29olaWI # remember, you excluded the first line\nhttp://ligman.me/29ngkYn\nhttp://ligman.me/29hV6ZM\nhttp://ligman.me/29d1qAV\nhttp://ligman.me/29pfpbI\nhttp://ligman.me/29v8nwX\nhttp://ligman.me/29uq452\nhttp://ligman.me/29d1wc3\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2017-07-17T18:21:59.000Z","url":"https://community.spiceworks.com/t/powershell-help-downloading-2016-ms-free-ebooks/593849/10","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"