Clickable hyperlink on PowerShell's console output

妖精的绣舞 提交于 2021-01-27 07:09:58

问题


I'm having some issues with the following PowerShell script, could you please help me with that?

What I'm trying to accomplish is create a clickable hyperlink in PowerShell's console output. Something like that:

$testOutPut = "http://something.com"
Write-Host $OutputConvertedIntoHYPERLINK

Where the desired console response would be:

clickable link to external app

 http://something.com

My goal with it is to show this clickable information on build console into TFS 2015.


回答1:


You can't do that but you can do to open internet explorer, with a specific URL:

$InternetExplorer=new-object -com internetexplorer.application
$InternetExplorer.navigate2("http://stackoverflow.com")
$InternetExplorer.visible=$true



回答2:


Clickable links, when referring to the PowerShell console window, are not supported by itself. While the PowerShell console can catch mouse clicks and such, interaction within the console (with the text output it displays) isn't capable of handling hypertext references like you want directly.

An alternative, since this is not feasible, would be to write to an HTML file, then launch said HTML file in a browser. Another consideration: implement something like PrimalForms, that adds the functionality of Windows-style designs to provide the clickable link for you.




回答3:


you can open chrome or FF to a specific page by using a start-process command

Start-Process "chrome.exe" "https://www.google.com"

So you could build on that and do something like this in the console:

Do {
    Write-Host "Open Google?" -ForegroundColor Yellow
    $result = Read-Host "   ( y / n ) " 
}Until ($result -eq "y" -or $result -eq "n")
if($result -eq "y"){
    Start-Process "chrome.exe" "https://www.google.com"
}


来源:https://stackoverflow.com/questions/36293078/clickable-hyperlink-on-powershells-console-output

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!