Download PDF with IE COM Object

时间:2016-04-15 15:00:39

标签: powershell internet-explorer pdf com

I've seem to hit a wall trying to download a PDF file.

Using PowerShells Internet Explorer COM Object, my script logs in to a web site and then navigates to the PDF document. Once on the PDF page, I have tried a couple recommended methods of downloading the file.

1) Using Invoke-WebRequest

Invoke-WebRequest -uri $PDFUrl -OutFile $Path.pdf

2) Pipe the current IE instance to my path, like so:

$ie.navigate($url)
Start-sleep -seconds 5
$ie | Out-File $Path.pdf

Both methods are outputting invalid PDF's (with no actual content). Am I missing something? Anyone know how I can get the PDF to properly download to my path?

Thanks in advance for any suggestions.

1 个答案:

答案 0 :(得分:0)

You can use System.Net.WebClient

$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url,$file)