Solved

Powershell Open Private browsing window

Posted on 2015-01-03
7
625 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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

728 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