Saving a web page from IE using Powershell

2019-02-18 07:35发布

问题:

I use the automation interface of Internet Explorer from Powershell to open a web page in a supported format. I want to save this page back to disk in one of the formats supported by IE. Opening the page is easy:

$ie = New-Object -ComObject "InternetExplorer.Application"
$ie.Navigate("C:\MyFile.mht")

How do I save it back in another format?

I need a solution that does not prompt the user since the idea is to automate this in a script running through multiple files.

回答1:

You want to call ExecWB with the appropriate args:

$ie.ExecWB(4,0,$null,[ref]$null)

Explanation of the 4 params:

4 = OLECMDID_SAVEAS
0 = OLECMDEXECOPT_DODEFAULT (This can also be 2 = OLECMDEXECOPT_DONTPROMPTUSER to not prompt and just save)
$null = NULL (I think this can be a path to save to: separate folders with 2 slashes (\\))
[ref]$null = ref NULL :)