How to open URL in Microsoft Edge from the command line?

前端 未结 12 701
天涯浪人
天涯浪人 2020-11-29 23:44

I need to open URL in Microsoft Edge (on Windows 10). When I invoke

start shell:AppsFolder\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe!MicrosoftEdge http://www.go         


        
12条回答
  •  醉梦人生
    2020-11-30 00:22

    Personally, I use this function which I created and put in my profile script ...\Documents\WindowsPowerShell\….profile, feel free to use it. As I am from the UK, I prefer to go to .co.uk where possible, if you are from another area, you can add your own country code.

    # Function taking parameter add (address) and opens in edge.
    Function edge {
        param($add)
        if (-not ($add -contains "https://www." -or $add -contains "http://www.")) {
            if ($add[0] -eq "w" -and $add[1] -eq "w" -and $add[2] -eq "w") {
                $add = "https://" + $add
            } else {
                $add = "https://www." + $add
            }
        }
    
        # If no domain, tries to add .co.uk, if fails uses .com
        if (-not ($add -match ".co" -or $add -match ".uk" -or $add -match ".com")) {
            try {
                $test = $add + ".co.uk"
                $HTTP_Request  = [System.Net.WebRequest]::Create($test)
                $HTTP_Response = $HTTP_Request.GetResponse()
                $add = $add + ".co.uk"
            } catch{
                $add = $add + ".com"
            }
        }
        Write-Host "Taking you to $add"
        start microsoft-edge:$add
    }
    

    Then you just have to call: edge google in powershell to go to https://www.google.co.uk

提交回复
热议问题