You can open a web URL in a web browser right away by pasting the URL string into the address bar and pressing Enter, but if you want to know how to access a web URL in a command line, batch file, or PowerShell script, you've come to the right place.
Table of Contents
- macOS X
Today, ourtechroom will show you how to use Powershell and Command to open a URL in a browser.
Windows provides sophisticated command-line tools. Command prompt and PowerShell are two of the most powerful tools available. Let's look at each of them.
Start Command in Windows Command Prompt
Command Prompt's Start Command is one of the most frequently used internal commands, and it is supported by all versions of Windows. Its primary function is to Open a file, app, URL etc.
It can be used in a batch file or on the command line.
Start Command is case insensitive. So, start and START are the same things.
This will open ourtechroom site in your default browser.
But following a web URL without HTTP, HTTPS, FTP, or www, does not work.
This does not work. Because in this case, Windows will treat stackoverflow.com as a folder and will not find the folder on that path and will give an error stating: Windows cannot find 'stackoverflow.com'.Make sure you typed the name correctly, and then try again.
So, note that it should begin with PROTOCAL:/ or www on the URL.So, that Command line will know the user is attempting to open the command line.
If you want to open Url in Chrome then type:
start chrome https://stackoverflow.com
If you want to open URL in Firefox then type:
start firefox https://stackoverflow.com
If you want to open Url in Microsoft Edge then type:
start msedge https://stackoverflow.com
If you want to run the "Start" command outside command, you have to do it like this.
Microsoft's Powershell is a strong tool for automating tasks and managing configurations. In Powershell, there are a number of ways to open a URL in a browser, some of which are outlined here.
Using Start-Process Command
A new process is created when you call Start-Process, which inherits the current process's Environment Variables.You can use start-process command in both PowerShell and PowerShell script (ps) files.
If you do not specify anything then by default it will open with the default browser.
This will open the stackoverflow.com website in new Windows. As I have set Chrome as the default browser so by default it will open the site in Google Chrome.
Start-Process Open in Internet Explorer
Start-Process -FilePath 'iexplore.exe' -ArgumentList 'https://www.stackoverflow.com/'
Start-Process Open in Chrome Browser
Start-Process chrome "https://www.stackoverflow.com"
Start-Process Open in Firefox
Start-Process -FilePath firefox -ArgumentList www.stackoverflow.com
Start-Process Open in Edge
Start-Process -FilePath msedge -ArgumentList www.stackoverflow.com
Alias Using Shorter Powershell
Start chrome '--start-fullscreen "http://www.google.com"'
Using Invoke-Expression command in PowerShell
According to Windows "The Invoke-Expression cmdlet evaluates or runs a specified string as a command and returns the results of the expression or command. Without Invoke-Expression, a string submitted at the command line is returned (echoed) unchanged".
ie. Invoke-Expression will take the string and then execute that string. The string can be anything that can be executable by Invoke-Expression.
Invoke-Expression “cmd.exe /C start https://stackoverflow.com”
'cmd.exe /C start https://stackoverflow.com' |Invoke-Expression
Open Multiple URLs using Powershell
You can open multiple URLs with one PowerShell command as shown below:
Here we are opening StackOverflow and ourtechroom sites in two different tabs in the browser.
$url1 = 'https://stackoverflow.com/'
$url2 = 'https://ourtechroom.com'
Write-Host "Oops, something went wrong!"
Start-Process -FilePath Chrome -ArgumentList '--new-window https://stackoverflow.com https://ourtechroom.com'
Powershell For IE:
Opening multiple URL in IE using Powershell command as shown below:
$navOpenInBackgroundTab = 0x1000;
$ie = new-object -com InternetExplorer.Application
$ie.Visible = $true;
What’s the difference between Invoke-Expression and Start-Process?
The start-Process cmdlet returns the results of the process that was run, and you can use it to interpret the results after that. Invoke-Expression is a quick and dirty process that does not return an object as a result of the executed process.
You can use the open command to open the URL in MacOS.
In Linux and Unix, you have to install the xdg-open commands installed. After you have installed you can go and run the following command in the terminal.
How do I use the command line to access a website's URL in a new tab within an existing browser window that is already open?
To access the URL in a new tab, you can use the "start" command with the "http://" or "https://" prefix and the URL as an argument. In addition, you can use the "/newtab" or "-new-tab" switch. For instance, to open the URL "https://www.ourtechroom.com" in a new tab of an already open window of Google Chrome, you can execute the command "start chrome.exe https://www.ourtechroom.com /newtab" by entering it into a command prompt. This will accomplish the desired result.
start chrome.exe https://www.ourtechroom.com /newtab
How do I open a web URL in a new tab of an already open browser window using PowerShell?
You can use the Start-Process cmdlet in conjunction with the "-ArgumentList" parameter to send the URL to the browser process that is already operating. This will cause the URL to be passed along as an argument. For instance, if you want to open the URL "https://www.google.com" in a new tab of an already open window of Google Chrome, you can do so by executing the instruction "Start-Process chrome.exe -ArgumentList '--new-tab https://www.ourtechroom.com'." This will cause the URL to be opened in the new tab.
Start-Process chrome.exe -ArgumentList '--new-tab https://www.ourtechroom.com