Solved

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

Posted on 2014-01-30
8
1,084 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 70

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 70

Accepted Solution

by:
Qlemo earned 250 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 250 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 70

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

A brief introduction to what I consider to be the best editor for PowerShell.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

695 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