Automating IE with PowerShell

Welcome Forums General PowerShell Q&A Automating IE with PowerShell

This topic contains 2 replies, has 3 voices, and was last updated by

 
Participant
2 years, 10 months ago.

  • Author
    Posts
  • #32472

    Participant
    Points: 0
    Rank: Member

    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

    Keymaster
    Points: 1,524
    Helping HandTeam Member
    Rank: Community Hero

    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

    Participant
    Points: 0
    Rank: Member

    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 {
         [DllImport("user32.dll")]
         [return: MarshalAs(UnmanagedType.Bool)]
         public static extern bool SetForegroundWindow(IntPtr hWnd);
      }
    "@
    
    $ie = Start-Process iexplore.exe -PassThru | Get-Process
    
    [void][Tricks]::SetForeGroundWindow($ie.MainWindowHandle)
        
        Start-Sleep -Seconds 2
    
    [System.Windows.Forms.SendKeys]::SendWait("{F12}")
    

The topic ‘Automating IE with PowerShell’ is closed to new replies.