Is it possible in one PowerShell line to start Microsoft Edge with multiple tabs?

huangapple go评论72阅读模式
英文:

Is it possible in one PowerShell line to start Microsoft Edge with multiple tabs?

问题

我想通过单个PowerShell命令在快捷方式中启动Microsoft Edge(Chromium)并打开多个选项卡。以下是适用于一个选项卡的有效命令:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& start microsoft-edge:https://www.outlook.com"

但我不清楚如何添加一组网站。类似于:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& start microsoft-edge:https://www.outlook.com;https://www.google.com"

这个命令不起作用,但我正在寻找类似这样的解决方案。请注意,我没有对我正在尝试执行此操作的工作站具有管理员访问权限。

英文:

I'd like to be able to start Microsoft Edge (Chromium) with multiple tabs via a single PowerShell command in a shortcut (not a script). Here is what I have that works for one tab:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& start microsoft-edge:https://www.outlook.com"

but I am unclear how to add on a set of sites. Something like:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& start microsoft-edge:https://www.outlook.com;https://www.google.com"

That doesn't work, but I'm looking for something along those lines. Note, I do not have admin access to the workstation where I'm trying to do this.

答案1

得分: 3

以下是您要翻译的内容:

"据我所知,只有在通过microsoft-edge:协议方案启动时才支持单个URL。

但是,您可以通过位于目录$env:LOCALAPPDATA\Microsoft\WindowsApps中的MicrosoftEdge.exe可执行文件来启动Edge,该可执行文件接受多个URL(在这种情况下请注意使用,分隔它们):

上述命令等同于(请注意使用了-Command CLI参数以及 Start-Process的完整名称和参数名称):

实际上,在这种情况下,对于基于可执行文件的调用,甚至不需要Start-Process,因为使用直接调用时,GUI可执行文件会以异步方式启动:

请注意,需要使用&,因为可执行文件路径包含变量引用,并且现在两个URL以_空格_分隔(作为单独的参数传递)。

相反,如果您希望在返回调用之前等待Edge关闭,通常会使用Start-Process -Wait,但是很遗憾,在PowerShell 7.3.3之前,对于AppX应用程序(如Microsoft Edge),这种方法通常不起作用 - 请参阅GitHub问题#10996。"

英文:

<!-- language-all: sh -->

As far as I'm aware, only a single URL is supported when you launch via the microsoft-edge: protocol scheme.

However, you can launch Edge via the MicrosoftEdge.exe executable located in directory $env:LOCALAPPDATA\Microsoft\WindowsApps, which does accept multiple URLs (note the need to separate them with , in this case):

powershell.exe &quot;start $env:LOCALAPPDATA\Microsoft\WindowsApps\MicrosoftEdge.exe https://example.org, https://google.com&quot;

The above is short for (note the use of the -Command CLI parameter and the use of Start-Process's full name and parameter names):

powershell.exe -Command &quot;Start-Process -FilePath $env:LOCALAPPDATA\Microsoft\WindowsApps\MicrosoftEdge.exe -ArgumentList https://example.org, https://google.com&quot;

In fact, with an executable-based invocation you don't even need Start-Process in this case, given that a GUI executable launches asynchronously even with direct invocation:

powershell.exe &quot;&amp; $env:LOCALAPPDATA\Microsoft\WindowsApps\MicrosoftEdge.exe https://example.org https://google.com&quot;

Note the need to use &amp;, because the executable path contains a variable reference, and that the two URLs are now space-separated (passed as individual arguments).


Conversely, if you wanted to wait for Edge to close again before returning from the call, you would normally use Start-Process -Wait, but this is not effective with AppX applications such as Microsoft Edge, unfortunately, at least as of PowerShell 7.3.3 - see GitHub issue #10996.

huangapple
  • 本文由 发表于 2023年4月13日 22:45:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76006821.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定