Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clickable hyperlink on PowerShell's console output

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.

like image 707
user1809439 Avatar asked Mar 29 '16 19:03

user1809439


3 Answers

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
like image 144
FannolGashi Avatar answered Nov 16 '22 04:11

FannolGashi


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"
}
like image 43
Sidupac Avatar answered Nov 16 '22 03:11

Sidupac


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.

like image 27
gravity Avatar answered Nov 16 '22 02:11

gravity