powershell script to open web address URL with default browser

After install a website, we used to open the start page in web browser.

There are at least (not 2) 4 ways to open web address URL with default browser in Powershell.

1. Run a exe file with parameter is our url.

How to get exe filepath of default browser? define and use this function (thanks to Ravikanth Chaganti):

Function GET-DefaultBrowserPath {
#Get the default Browser path
New-PSDrive -Name HKCR -PSProvider registry -Root Hkey_Classes_Root | Out-Null
$browserPath = ((Get-ItemProperty ‘HKCR:\http\shell\open\command’).'(default)’).Split(‘”‘)[1]
return $browserPath
}

call

Get-DefaultBrowserPath

in my computer Powershell console will return D:\Program Files (x86)\Mozilla Firefox\firefox.exe

2. Simple way:

call

start ‘http://www.gurucore.com’

in Powershell.

Thanks Dac Thach, I tested your solutions and it works on Windows 2008 + Powershell 1.0

3. One another is we use Invoke-Expression

to lend the Windows’ CMD hand (like you open Windows Run / cmd / then type start)

 

Invoke-Expression “cmd.exe /C start http://gurucore.com
Invoke-Expression “cmd.exe /C start http://some-thing.com.net/~en/my-site/gurucore.com#thach
Invoke-Expression “cmd.exe /C start /b http://gurucore.com?ab=abb’&’thach=2+g~

4. Use .NET static function

[Diagnostics.Process]::Start(‘http://gurucore.com?a=-b&c=~d#abc’,’arguments‘)

4 thoughts on “powershell script to open web address URL with default browser

  1. Is there any way to do this in a non memory leak automated way? Having IE started for every request and leaving it open does not seem to be the best way in my opinion.

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