将Microsoft Edge设置为powershell的默认浏览器



我正在编写一个脚本,将默认浏览器更改为Microsoft Edge,我已经这样做了:

function Set-DefaultBrowser {
Add-Type -AssemblyName 'System.Windows.Forms'
Start-Process $env:windirsystem32control.exe -LoadUserProfile -Wait -ArgumentList '/name Microsoft.DefaultPrograms /page pageDefaultProgrampageAdvancedSettings?pszAppName=MSEdgeHTM'
Sleep 10
[System.Windows.Forms.SendKeys]::SendWait("{TAB}{TAB}{TAB}{TAB}{TAB} {ENTER}{ENTER} ")
}
Set-DefaultBrowser

但是我不喜欢,就像一个人在那里做它打开菜单之类的东西,我想这样做,而不是像那样显示它,可以这样做吗?

我的建议是设置控制默认浏览器的Regkeys。这里有一个链接到一个帖子,展示如何使用Chrome

https://itectec.com/superuser/cmd-command-to-set-chrome-as-default-browser-windows-10/

你会注意到需要的命令,但将应用程序名称更改为Edge

Set-ItemProperty -Path 'HKCU:SOFTWAREMicrosoftWindowsShellAssociationsUrlAssociationshttpsUserChoice' -Name ProgId -Value 'ChromeHTML'
Set-ItemProperty -Path 'HKCU:SOFTWAREMicrosoftWindowsShellAssociationsUrlAssociationshttpUserChoice' -Name ProgId -Value 'ChromeHTML'