Skip to content

Instantly share code, notes, and snippets.

Last active May 24, 2023 17:50
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Download all PDF's from a web page via PowerShell
# More information at
function Grab-PDFs {
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
$browse = New-Object System.Windows.Forms.FolderBrowserDialog
$browse.SelectedPath = "C:\"
$browse.ShowNewFolderButton = $false
$browse.Description = "Select a directory"
$loop = $true
if ($browse.ShowDialog() -eq "OK")
$loop = $false
cd $browse.SelectedPath
#Scrape Web Page for PDFs
$psPage = Invoke-WebRequest ""
$urls = $psPage.ParsedHtml.getElementsByTagName("A") | ? {$_.href -like "*.pdf"} | Select-Object -ExpandProperty href
$urls | ForEach-Object {Invoke-WebRequest -Uri $_ -OutFile ($_ | Split-Path -Leaf)}
Write-Host "... PDF downloading is complete."
[System.Windows.Forms.MessageBox]::Show("Your PDFs have been downloaded.", "Job Complete")
} else
$res = [System.Windows.Forms.MessageBox]::Show("You clicked Cancel. Would you like to try again or exit?", "Select a location", [System.Windows.Forms.MessageBoxButtons]::RetryCancel)
if($res -eq "Cancel")
#Ends script
} Grab-PDFs
Copy link

does this work recursively for child pages.

Copy link

Good one.

Copy link

jersam commented Jun 24, 2020

I get the following.

Invoke-WebRequest : The URI prefix is not recognized.
At C:\Users\Administrator\Desktop\PDF_Grabber.ps1:25 char:27
+ ... ach-Object {Invoke-WebRequest -Uri $_ -OutFile ($_ | Split-Path -Leaf ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException
    + FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment