?
Solved

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

Posted on 2014-01-30
8
Medium Priority
?
1,108 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 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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

This article will help you understand what HashTables are and how to use them in PowerShell.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

770 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