?
Solved

Powershell Open Private browsing window

Posted on 2015-01-03
7
Medium Priority
?
664 Views
Last Modified: 2015-01-09
Code below opens an IE window for automation process
if (!(Get-Variable ie -Scope global -ea SilentlyContinue) -or !$ie.Document)
{
  $global:ie = New-Object -comobject InternetExplorer.Application
}
$ie.visible = $true
$ie.silent  = $true

Open in new window



My Question is how would I change code above to open a Private browsing IE window instead?
0
Comment
Question by:Leo Torres
[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
  • 4
  • 2
7 Comments
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40528946
Unfortunately not and you can not even get a handle to an existing running IE window using [Runtime.InteropServices.Marshal]::GetActiveObject()

Otherwise you could launch with something like..

Start-Process -FilePath "C:\Program Files (x86)\Internet Explorer\iexplore.exe" -ArgumentList ' -private http://www.experts-exchange.com/'

Open in new window

0
 
LVL 8

Author Comment

by:Leo Torres
ID: 40529922
The thing is that this just opens a IE. I need to have powershell to have control of IE browser window to traverse page.

Here what I am doing with that session. I need a private window though.

if (!(Get-Variable ie -Scope global -ea SilentlyContinue) -or !$ie.Document)
{
  $global:ie = New-Object -comobject InternetExplorer.Application
}
$ie.visible = $true
$ie.silent  = $true

$global:ReportPart = "/interface/folderTree.jsp?rootId=216&expandLevel=1&clearUIPath=true&uiPathLabel=Reports"

function Test-ReportSite ([String] $url, [String] $login, [String] $password)
{
  $ie.Navigate2($url)
  while ($ie.busy)                               { Start-Sleep -m 100 }
  while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }
   
  $ie.Document.getElementsByTagName("input")  | ? { $_.Id   -eq 'loginField'    } | % { $_.value = $login    }
  $ie.Document.getElementsByTagName("input")  | ? { $_.Id   -eq 'passwordField' } | % { $_.value = $password }
  $ie.Document.getElementsByTagName("button") | ? { $_.Type -eq 'button'        } | % { $_.Click() }
  while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }
  
  $ie.Navigate2($url + $ReportPart)
  while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }

  $link = $ie.Document.getElementsByTagName("a") | ? { $_.InnerText -like '*Overtime Report' }  |  select  -First 1 -expandProperty href
  if(!$link) {          
  	$link = $ie.Document.getElementsByTagName("a") | ? { $_.InnerText -like '*Count' }  |  select  -First 1 -expandProperty href           
  }
  $ie.Navigate2($link)
  while ($ie.Document.readyState -ne 'Complete') { Start-Sleep -m 100 }
   
  $ie.Document.getElementsByTagName("button") | ? { $_.innerText -eq 'Go' } | % { $_.Click() }
  Start-Sleep 5

<#  Error message evaluation ignored ATM   
  $ie.Document.getElementsByTagName("span") | ft -a classname, tagname, innerText #Gets you error
#>

  $RunByTest = $ie.Document.body.tagname -eq 'FRAMESET' -and $ie.Document.body.id -eq 'reportViewerFrame'

  if($RunByTest) {
      $TestValue = 200          
  }
  else {          
     $TestValue = -200
  }
  Write-Host "$URL`: $TestValue" 
  return $TestValue
}
                                          

Open in new window

0
 
LVL 70

Expert Comment

by:Qlemo
ID: 40529954
For what reason do you need a private IE? Probably you want to disallow caching of the credentials.
I've seen AutoHotkey code sending a Windows Message to make the IE private, but don't know whether that works, and how to convert to PowerShell (yet).
0
Need protection from advanced malware attacks?

Look no further than WatchGuard's Total Security Suite, providing defense in depth against today's most headlining attacks like Petya 2.0 and WannaCry. Keep your organization out of the news with protection from known and unknown threats.

 
LVL 8

Author Comment

by:Leo Torres
ID: 40530020
Has to do with cookie created during a session for some sites that causes issues.

Disallowing caching may work. How does the current command change.
0
 
LVL 70

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 40530063
Seems not to be easy at all. But first I would try to call $ie.Refresh2(3) to force a refresh, ignoring the cache.
0
 
LVL 8

Author Comment

by:Leo Torres
ID: 40539568
Added it at the top of the function.

function Test-ReportSite ([String] $url, [String] $login, [String] $password)
{
  $ie.Refresh2(3) #Here it is
  $ie.Navigate2($url)

Open in new window

0
 
LVL 8

Author Closing Comment

by:Leo Torres
ID: 40539569
I will go with this for now. Thank you!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
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…

764 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