Solved

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

Posted on 2014-01-30
8
1,071 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
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 

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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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