• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1150
  • Last Modified:

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

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
SURESH0518
Asked:
SURESH0518
  • 3
  • 3
2 Solutions
 
QlemoC++ DeveloperCommented:
$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
 
SURESH0518Author Commented:
Thank You. Could you provide fullcode how to search a particular string in .mhtml file. Any help is appreciated.
0
 
QlemoC++ DeveloperCommented:
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
SMB Security Just Got a Layer Stronger

WatchGuard acquires Percipient Networks to extend protection to the DNS layer, further increasing the value of Total Security Suite.  Learn more about what this means for you and how you can improve your security with WatchGuard today!

 
SURESH0518Author Commented:
This is excellent. It worked out and thanks a lot
0
 
Rainer JeschorCommented:
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
 
SURESH0518Author Commented:
I just want to search a string in .mhtml file and above code works perfectly
0
 
QlemoC++ DeveloperCommented:
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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now