Powershell-With-IE


Automate Internet Explorer to open a web site using PowerShell?
Script to automate Internet Explorer to open a site.

Please below three simple steps to open any website in Internet Explorer.

1.Create ie variable and assign ie ComObject using new-object cmdlets.

$ie = New-Object -ComObject InternetExplorer.Application

2. The next step is to navigate to the URL using Navigate method exposed by Internet Explorer object model and specify website address in it. Like 'http://www.google.com' here
Please use complete website address here.

$ie.Navigate("http://www.google.com")

3. By creating the object will not display the Internet Explorer. To make it visible, use Visible property of IE object as given below:

$ie.Visible = $true

Example

$ie = New-Object -ComObject InternetExplorer.Application
$ie.Navigate("http://www.google.com")
$ie.Visible = $true

Copy and Try it

Powershell IE automation getElementByID

Example

$someurl=some url
$ie = new-object -com "InternetExplorer.Application"
$ie.visible = $true
$ie.navigate($someurl)
$doc = $ie.Document
$element = $doc.getElementByID("username")

Copy and Try it

Modify Internet Explorer Settings You can modify Internet Explorer configuration setting using powershell or using simple powershell script to clean up your browser history. To modify the Internet Explorer configuration registry keys you need to use the Set-ItemProperty cmdlet.

For example, to update the proxy: Set-Location "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" Set-ItemProperty -Name ProxyServer -Value http://company.server.com Set-ItemProperty -Name ProxyEnable -Value 1 Discussion Internet Explorer stores its main configuration information as properties on the registry key HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings. To change these properties, use the Set-ItemProperty cmdlet as demonstrated in the Solution.

Add a Site to an Internet Explorer Security Zone

To List the InternetExplorer Methods So lets get started

Example

      
$ie = new-object -Com internetExplorer.application 
$ie | Get-Member -MemberType method | Out-File iemethods.txt

Copy and Try it

Example

Name           MemberType Definition
----           ---------- ----------
ClientToWindow Method     void ClientToWindow (int, int)
ExecWB         Method     void ExecWB (OLECMDID, OLECMDEXECOPT, Variant, Variant)
GetProperty    Method     Variant GetProperty (string)
GoBack         Method     void GoBack ()
GoForward      Method     void GoForward ()
GoHome         Method     void GoHome ()
GoSearch       Method     void GoSearch ()
Navigate       Method     void Navigate (string, Variant, Variant, Variant, Variant)
Navigate2      Method     void Navigate2 (Variant, Variant, Variant, Variant, Variant)
PutProperty    Method     void PutProperty (string, Variant)
QueryStatusWB  Method     OLECMDF QueryStatusWB (OLECMDID)
Quit           Method     void Quit ()
Refresh        Method     void Refresh ()
Refresh2       Method     void Refresh2 (Variant)
ShowBrowserBar Method     void ShowBrowserBar (Variant, Variant, Variant)
Stop           Method     void Stop ()

Copy and Try it

So now you know the methods you can call these methods to do required operations. Like we used Navigate in the initial example.
e.g. to go home you can call GoHome method it will take you to home page.