Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to Open an mhtml file using internet explorer using PowerShell Script

Posted on 2014-01-30
8
Medium Priority
?
1,128 Views
Last Modified: 2014-02-23
I need to open mhtml file using internet explorer using PowerShell Script and search for a particular string. Is this possible in PowerShell script
0
Comment
Question by:SURESH0518
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
8 Comments
 
LVL 71

Expert Comment

by:Qlemo
ID: 39820757
$ie = new-object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate("file://c:/path/to/file.mhtml")
while ($ie.busy) {sleep -milliseconds 50}

Open in new window

is the basic code to open a file or web site, and wait until completed. After that, you can access the content via $ie.
0
 

Author Comment

by:SURESH0518
ID: 39820772
Thank You. Could you provide fullcode how to search a particular string in .mhtml file. Any help is appreciated.
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 1000 total points
ID: 39820849
If you want to search the text only, which is likely (no HTML tags):
$ie.document.body.innerText -like '*something*'

Open in new window

will result in $true if "something" is found, else $false.
0
Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

 

Author Comment

by:SURESH0518
ID: 39820923
This is excellent. It worked out and thanks a lot
0
 
LVL 44

Assisted Solution

by:Rainer Jeschor
Rainer Jeschor earned 1000 total points
ID: 39820945
Hi,
and what do you want to get? Just search and if the string is in then a TRUE?
Any specific selection (e.g. Textbox,...)?

This returns true or false depending on the body html content:
$testfile = "file://d:/TestIEPS.mht"
$ie = new-object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate($testfile)
while ($ie.busy) {sleep -milliseconds 50} 
$docBodyHtml = $ie.document.body.innerHtml
$docBodyHtml -match "FREETEXTTABLE"

Open in new window

The MHT file was created from this MSDN page:
http://msdn.microsoft.com/en-us/library/ms177634.aspx

HTH
Rainer
0
 

Author Comment

by:SURESH0518
ID: 39822945
I just want to search a string in .mhtml file and above code works perfectly
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 39823411
Did you select the wrong comment? In http:#a39820923 you thanked me, but accepted a different Expert's comment, without any obvious reason. The solutions are not really different.
0

Featured Post

Looking for the Wi-Fi vendor that's right for you?

We know how difficult it can be to evaluate Wi-Fi vendors, so we created this helpful Wi-Fi Buyer's Guide to help you find the Wi-Fi vendor that's right for your business! Download the guide and get started on our checklist today!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A brief introduction to what I consider to be the best editor for PowerShell.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question