Open a webpage from PowerShell

The day might come when you need to open a webpage from PowerShell. It might be when a user clicks on a link in a graphical UI you’ve created or when a task has been completed in one of your scripts.

Doing this is very simple, all you need to do is to add the following one line of code to your script:

[System.Diagnostics.Process]::Start("http://www.guidestomicrosoft.com/")

When this part is run, the default browser will open up the webpage in a new tab.

If the webpage you are opening is compatible in IE only, or you wan’t it to open in IE for another reason, you need to extend the script a little bit.

The first thing we need to do is to get an object of the Internet Explorer application.
To do this, we use the following line:

$IE = New-Object -ComObject InternetExplorer.Application

InternetExplorer.Application is the ProgramID of the application we will start and to set the webpage that should open, we use the following line:

$IE.Navigate("http://www.guidestomicrosoft.com/")

As you can see, nothing happens. This is because we have only created the the object and called the method to navigate to a specific site. The next and final step is to show the object, in this case Internet Explorer:

$IE.Visible = $true

For more guides, click here!

This entry was posted in Powershell and tagged , , , . Bookmark the permalink.

1 Response to Open a webpage from PowerShell

  1. Pingback: PowerShell Guides - A guide to Microsoft ProductsA guide to Microsoft Products

Leave a Reply

Your email address will not be published. Required fields are marked *