Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

Use Internet Explorer in PowerShell

Posted on May 23, 2006August 5, 2009

Here's a PowerShell Script that demonstates how to create COM objects in PowerShell, in this case an Internet Explorer instance. The script then takes the output of the Get-Service cmdlet and writes the results to the IE window.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

# IEServiceList.ps1
# Jeffery Hicks
# http://jdhitsolutions.blogspot.com
# http://www.jdhitsolutions.com
# May 2006
#Display all running services in an Internet Explorer window

new-variable html
#create an object with the running services
$svc = get-service | where {$_.status -eq "running"}

#create a new COM object that is Internet Explorer
$oIE=New-object -COM InternetExplorer.Application

# If you want to see what Internet Explorer methods and
# properties exist, then run from within this script:
#$oIE |get-member

#Configure IE object
$oIE.navigate2("about:blank")
$oIE.width=400
$oIE.height=600
$oIE.Resizable=$True
$oIE.StatusBar=$True
$oIE.AddressBar=$False
$oIE.MenuBar=$False
$oIE.Toolbar=$False

#build the html code to display
foreach ($s in $svc) {$html=$html+"<font face=Verdana size=2>"+`
$s.Displayname+": "+$s.status+"</font><br>"}

#set the body with our html code
$oIE.document.body.innerHTML=$html

#display a summary in the status bar
$oIE.StatusText=($svc.Count).ToString()+" running services"

#display the IE object
$oIE.Visible=$True

Technorati Tags:
PowerShell
Scripting


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

14 thoughts on “Use Internet Explorer in PowerShell”

  1. Anonymous says:
    July 14, 2006 at 3:13 am

    Great post ! One of the first script I ran on PowerShell… I am getting the following error: Property ‘innerHTM:’ cannot be found on this object; make sure it exists and is settable. Am I missing something?

  2. Jeffery Hicks says:
    July 14, 2006 at 8:25 am

    I just retested and it still works for me. I wonder if something didn’t get copied right, assuming you cut and pasted from the blog. Try commenting out these lines:

    $oIE.document.body.innerHTML=$html

    and

    $oIE.StatusText=($svc.Count).ToString()+” running services”

    You should just get a blank IE window to display. If not then the new object isn’t getting properly created. You might uncomment

    #oIE | Get-member

    which should list properties and methods for object. If you get nothing or an error then double-check the line

    $oIE=New-object -COM InternetExplorer.Application

    which should be all one one line.

    Finally, I’m assuming Internet Explorer normally works on your computer and hasn’t been disabled in any way.

  3. Anonymous says:
    July 14, 2006 at 2:24 pm

    Hi Jeffery,

    Thanks for taking the time to answer. I tried the script again on another machine and got the same result. Everything is working (ie the blank IE windows shows up, and I got the correct summary in the status bar…) but the windows stays blank. The only line of code not working for me is:

    $oIE.document.body.innerHTML=$html

    If I comment it out, I do not get the error message. Thanks!

  4. Jeffery Hicks says:
    July 14, 2006 at 2:46 pm

    What OS are you running on? What version of Internet Explorer? I have not tried this with IE7. Unfortunately I’m going to be out of town all next week starting tomorrow with basically no Internet. I’ll have to see what else I can come up. If you want, email me the script you are using as a text file. Maybe there’s something in the way you have the file formatted.

  5. Karl says:
    July 18, 2006 at 11:19 am

    Hi Jeffery,

    Looks like a useful piece of scripting , unfortunately I’m also experiencing the exact same as the other comment.

    It appears that the COM object is being created, However Powershell can’t ref the property innerHTML.

    What version of Powershell are u using? i.e MSH beta or PSH?

    One also note, with the aid of ShinyPower (fantastic tool), the option -com doesn’t exists, however -comObject does, which seem to further the idea that you developed this potentially useful script in an earlier version.

    Lookforward to your reply.

    P.S How’s the Powershell book coming along?

    Kind regards

    Karl

  6. Karl says:
    July 18, 2006 at 11:21 am

    Hi Jeffery,

    Looks like a useful piece of scripting , unfortunately I’m also experiencing the exact same as the other comment.

    It appears that the COM object is being created, However Powershell can’t ref the property innerHTML.

    What version of Powershell are u using? i.e MSH beta or PSH?

    One also note, with the aid of ShinyPower (fantastic tool), the option -com doesn’t exists, however -comObject does, which seem to further the idea that you developed this potentially useful script in an earlier version.

    Lookforward to your reply.

    P.S How’s the Powershell book coming along?

    Kind regards

    Karl

  7. Jeffery Hicks says:
    July 19, 2006 at 8:02 pm

    I’m using the latest version but it was an upgrade (I believe) over the last beta. As I mentioned in earlier comments, if you’re getting the IE object created then -com vs -comobject shouldn’t be the issue. I’ll have to look when I’m back at home.

    Oh, and the book is really coming along. We’re in tech and copy edit mode. I think the plan is for a publish date early fall.

  8. Jeffery Hicks says:
    July 19, 2006 at 8:27 pm

    I had someone else test and he had no problem. I’d still like someone to send me copy of the script they are trying to run ([email protected]) so I can see if something is getting snafu’d in copying from the blog to a script. Also tell me what version of IE and what OS you are running.

  9. Jeffery Hicks says:
    July 25, 2006 at 12:50 pm

    The innerHTML method does not work with IE7 so if you are trying this on Vista it probably won’t work.

  10. Jeff Birk says:
    June 12, 2007 at 9:58 am

    I ran into the same problem, but found an answer on a different website. If you replace the following line:
    $oIE.document.body.innerHTML=$html

    with this one:
    $oIE.document.write(“$html”)

    I was able to get it working. I found the tip from the following website:
    http://www.vistax64.com/powershell/13956-innerhtml-method-not-working.html

  11. Stuart says:
    September 6, 2007 at 6:30 pm

    Hi Jeff, no need to construct the HTML. Just pipe the object into ConvertTo-HTML like this:
    $svc = get-service | where {$_.status -eq “running”} | ConvertTo-Html

    Much better!

  12. Jeffery Hicks says:
    September 7, 2007 at 8:37 am

    The point of the post was to demonstrate using COM objects in PowerShell. I was using IE as a viewer. When the script ended, nothing would be left behind. You can achieve the same results with an expression like this:

    PS C:\> get-service | where {$_.status -eq “running”} | select name | convertto-html | out-file c:\reports\running.html

  13. spenniec says:
    October 20, 2008 at 8:07 pm

    How could you then print out the Internet Explorer window from the script?

  14. Jeffery Hicks says:
    October 21, 2008 at 8:44 am

    I’m not aware that the IE COM object has a print method.

    I encourage you to post your script and problem in the PowerShell forum at ScriptingAnswers.com.

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d