Controlling Internet Explorer object from PowerShell

  • Comments 12

NOTE: The site must be in the Trusted Sites Zone for this script to work - James Brundage [MSFT] January 5th, 2009

The following example shows how to display all the processes in an IE window and highlight the ones with memory usage of greater than or equal to the specified value.

$oIE=new-object -com internetexplorer.application
while ($oIE.busy) {
    sleep -milliseconds 50
$procList=ps |select-object ProcessName,Handles,NPM,PM,WS,VM,CPU,Id |convertto-html

$oDocBody=$oIE.document.documentelement.lastchild ;

#populate the document.body

$"12pt Arial";

#Reading back from IE.
$oTBody=@($oIE.document.getElementsByTagName("TBODY"))[0] ;
foreach ($oRow in $oTBody.childNodes)
   #check the 4 column(WS),and highlight it if it is greater than 5MB.
   $WS=(@($oRow.childNodes)[4].innerhtml) -as [int]  ;
   if (($ws -ne $null) -and ($WS -ge 5mb)) {
       $oRow.bgColor="#AAAAAA" ;

#Prepare a title.
$"bold 20pt Arial"
$oTitle.innerhtml="Process List";
$oTitle.align="center" ;

#Display the title before the Table object.
$oTable=@($oIE.document.getElementsByTagName("TABLE"))[0] ;
$oDocBody.insertBefore($oTitle,$oTable) > $null;

Displaying the “$procList”  can also be accomplished with “write” methods instead of innerhtml assignment.  But we should perform some extra checks to determine  whether the document.body  is type of [mshtml.htmldocumentclass]. If the “htmlfile” progid has the following settings in the registry:


Class        : mshtml.HTMLDocumentClass
Assembly  : Microsoft.mshtml, Version=7.0.3300.0,  Culture=neutral,       PublicKeyToken=b03f5f7f11d50a3a

then, mshtml.htmldocumentclass become .NET wrapper for the document.body object.
So the following line :

Can be replaced with:

If ($oIE.document.psbase.tostring() –eq “system.__comobject”) {
else {
$oDocBody=$oIE.document.documentelement.lastchild ;


Yuksel Akinci [MSFT]
Windows PowerShell Team
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.


Leave a Comment
  • Please add 3 and 5 and type the answer here:
  • Post
  • Is it possilbe to create additional tabs in the same browser window, for additional or differnet information about the same request?
  • I get this error:

    >> {
    >>    #check the 4 column(WS),and highlight it if it is greater than 5MB.
    >>    $WS=(@($oRow.childNodes)[4].innerhtml) -as [int]  ;
    >>    if (($ws -ne $null) -and ($WS -ge 5mb)) {
    >>        $oRow.bgColor="#AAAAAA" ;
    >>    }
    >> }
    Bad numeric constant: 5mb.

    I changed it to 5*1024*1024 and it seems to be good now.
  • you can just drop "b" in "5mb" and everything will work fine.
  • ActiveMode: I don't believe IE exposes their tab management through their COM scripting API.

  • It is possible to control IE Print Setting (Internet - Options - Printing - Print background colors and images) from PowerShell? Thanks.
  • Inspired by tis article, I'm trying without success to simply access form powershell to elements of an html page, here's the code:

    $oIE=new-object -com internetexplorer.application



    format-default : La référence d'objet n'est pas définie à une instance d'un objet.

    (sorry for the french error message, I do not know to make powershell speaks english everytime)

  • Is it possible to control Pop-up Blockers using PowerShell?

  • Would it be possible to measure the amount of time that it takes to download "" and its objects? (jpgs, and/or gifs)



  • How to access website using login and password credentials with Powershell


  • How to access website using login and password credentials with Powershell



  • How could I set the Only Open First Home Page when IE starts option??

  • When I try this, I get a popup in IE that says

    Stop running this script?

    A script on this page is causing your web browser to run slowly.  If it continues your computer might become unresponsive

Page 1 of 1 (12 items)

Controlling Internet Explorer object from PowerShell