How do I access the classic Internet Explorer COM automation object for a running instance of Internet Explorer from Powershell? How do I access the classic Internet Explorer COM automation object for a running instance of Internet Explorer from Powershell? powershell powershell

How do I access the classic Internet Explorer COM automation object for a running instance of Internet Explorer from Powershell?


Usually, to obtain access to a COM interface on an existing object, you would use the running object table. Unfortunately, Internet Explorer doesn't register itself with the running object table - but nevertheless, this provides us with some useful Google search results.

For example, Googling "running object table" "internet explorer" found me How to connect to a running instance of Internet Explorer which provides a (VBScript?) sample demonstrating the use of the ShellWindows object.

A quick 'n dirty (no error checking!) translation of this sample to PowerShell script gives us:

$shellapp = New-Object -ComObject "Shell.Application"$ShellWindows = $shellapp.Windows()for ($i = 0; $i -lt $ShellWindows.Count; $i++){  if ($ShellWindows.Item($i).FullName -like "*iexplore.exe")  {    $ie = $ShellWindows.Item($i)    break  }}$ie.navigate2("http://stackoverflow.com")