How to automate Internet Explorer to open a web site using PowerShell?

This is a simple fun script to automate Internet Explorer to open a site. This will also give an idea on how to use automation using PowerShell. Here I will explain how to open www.bing.com in Internet Explorer.

The first step is to get an object of Internet Explorer Application. For that we can use New-Object cmdlet as given below:

$ie = New-Object -ComObject InternetExplorer.Application

Let us see what the code does.
New-Object cmdlet creates a new object and returns it.
-ComObject parameter specifies that the new object is a COM object. When -ComObject parameter is passed, it takes the ProgId of the COM class registered. Otherwise, this is used to create an instance of a .NET Framework Class.
InternetExplorer.Application is the ProgId used for creating a new object.

Once the object is retreived, we can use the methods exposed by the object model of that application for automation.

The next step is to navigate to the URL using Navigate method exposed by Internet Explorer object model. Use the code given below to call Navigate method.

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

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

The values should be preceded by $ sign as in $true
So the full code goes like this:

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

You can either run this script in PowerShell command window or save this code in a script file (PS1) file and execute it in PowerShell.

Now you know how to automate Internet Explorer in PowerShell.
Happy Scripting !!!

About these ads

About sreerenjnair
Hi!! I am Sreerenj Nair working in Bangalore. I will update my details later. Have a nice day!!

One Response to How to automate Internet Explorer to open a web site using PowerShell?

  1. Pingback: How to run a PowerShell Script « Sreerenj Nair

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: