Create a Function to Open Internet Explorer (Like in Run)

Even before Windows PowerShell, I strove to do things quickly. One such thing was to open Internet Explorer (IE) from the Run dialog. In the image below, you can see how you can enter iexplore followed by a space and then a URL. When you press OK, it will launch IE and direct itself to the URL that was passed along. If no URL is provided, it will open the home page.

Create Function to Open Internet Explorer (Like in Run)01

When I transferred this knowledge to PowerShell, I was sad to see that entering the same thing in the console host resulted in an error: “The term ‘iexplore’ is not recognized as the name of a cmdlet, function, script file, or operable program.”  I wasn’t overly concerned about it, moved on, and mostly forgot about it.

After spending last week at the PowerShell Summit North America 2015, I saw several demos from speakers that included ‘start iexplore <URL>,’ where start is an alias for Start-Process. Use Get-Alias to see this yourself: Get-Alias -Name start. I decided I would write up a simple function, to add to my profile, that would allow me to just use iexplore again.

With the function below, in place, I can enter iexplore in PowerShell to open Internet Explorer to the home page, or iexplore bing.com to open Internet Explorer to bing.com, for example — pretty straightforward. Here it is: the little function that saves me six keystrokes every time I use it. Don’t worry, it won’t be long before I make up for the lost keystrokes from writing the function itself.

Function iexplore {
	Param ([string]$Url)

	If ($Url) {
		start iexplore $Url
	} Else {
		start iexplore
	}
}

And, here’s the results.

Create Function to Open Internet Explorer (Like in Run)02

Before we close for the day, we should probably makes a couple changes to our function. We should change the function name so it uses an approved verb, along with the verb-noun naming convention, and then create an alias (iexplore), to call the function.

Set-Alias -Name iexplore -Value Open-InternetExplorer

Function Open-InternetExplorer {
	Param ([string]$Url)

	If ($Url) {
		start iexplore $Url
	} Else {
		start iexplore
	}
}

Leave a Reply

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