PowerShell, Test if Internet Explorer has initialised

49 Views Asked by At

A recurring problem that I have on every new system is that my PowerShell scripts will break on running Invoke-WebRequest due to the incredibly frustrating requirement that this Cmdlet cannot run until Internet Explorer has initialised. I would appreciate how we should script around and understand the following points:

  • How to test (in PowerShell) if Internet Explorer has been initialised?, and

  • A clean and simple and silent way to initialise Internet Explorer in the background so that my scripts don't break and can continue to run?

  • Also, I'm utterly confused on this one: Why are we still beholden (in 2020!) to the ancient, insecure and essentially useless application that is Internet Explorer?

The problem manifests itself with the following error if Invoke-WebRequest is run when IE has not been run:

Invoke-WebRequest : The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer's first-launch
configuration is not complete. Specify the UseBasicParsing parameter and try again.
At C:\Users\Boss\Documents\WindowsPowerShell\Modules\Custom-Tools\Custom-Tools.psm1:8677 char:13
+     $page = Invoke-WebRequest -uri $url
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotImplemented: (:) [Invoke-WebRequest], NotSupportedException
    + FullyQualifiedErrorId : WebCmdletIEDomNotSupportedException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
0

There are 0 best solutions below