Automating IE with PowerShell


This topic contains 2 replies, has 3 voices, and was last updated by Profile photo of Matt Bloomfield Matt Bloomfield 10 months, 3 weeks ago.

  • Author
  • #32472
    Profile photo of Anthony Baron
    Anthony Baron

    I am building some tools to help capturing some critical management system configuration information and I hit a snag with IE. We need to run IE in the F12 debug mode where it captures application log files and these then need to be uploaded and analyzed. While I know how to automate some IE activities with PowerShell, there does not seem to be a way to automate starting IE followed by the F12 key. Also I don't see a way of redirecting the output with PowerShell. Is anyone aware of a good resource (IE PowerShell documentation) that can help with this. I assume that lots of people drive IE with PowerShell but I am finding it hard to find a good source to solve my problem.

    Thanks in advance.

  • #32559
    Profile photo of Don Jones
    Don Jones

    Correct. That IE COM object is ancient, and no longer developed by Microsoft. They quit paying attention to it long before adding the Debug mode to the browser, and so the COM object doesn't support it. A lot of people do automate IE using PowerShell, and most of them end up with their heads planted against a brick wall from time to time.

  • #32639

    I was having a think about this and figured that you could probably 'hit' F12 with SendKeys. I had a problem changing the focus of the Window but this stackoverflow post helped there. Does this help at all?

    Add-Type @"
      using System;
      using System.Runtime.InteropServices;
      public class Tricks {
         [return: MarshalAs(UnmanagedType.Bool)]
         public static extern bool SetForegroundWindow(IntPtr hWnd);
    $ie = Start-Process iexplore.exe -PassThru | Get-Process
        Start-Sleep -Seconds 2

You must be logged in to reply to this topic.