Home > Enterprise >  open HTML from PowerShell with URL parameters
open HTML from PowerShell with URL parameters

Time:05-14

I am trying to open a HTML file in Microsoft Edge browser from PowerShell.

Below code opens HTML in Microsoft edge

&'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe' @('d:\test.html')

How to pass some values from PowerShell to HTML using URL parameters. I wanted something like below code

&'C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe' @('d:\test.html?testvalue1=45&testvalue2=50')

But the above code opens browser but cannot able to load test.html. Using JavaScript I want to get values from URL which is passed by PowerShell.

CodePudding user response:

One way to accomplish this is to use the "Start-Process" cmdlet

Start-Process 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe' C:\Web\index.html

This however only works if you know the path. For some reason Powershell fails to translate for example .\index.html to a proper path.

CodePudding user response:

You could try the command below.

Start-Process microsoft-edge:"https://localhost?testvalue1=45&testvalue2=50"

Output:

enter image description here

  • Related