Hyperlinks in Powershell Script

Oliver Fung 21 Reputation points
2023-01-11T08:56:13.07+00:00

I have a powershell script that loads computer names and displays a table of a few properties then converts it to an HTML file. One column I'm trying to get is hyperlinks so that when you click on it, it sends you to a url in the format of winserver.adatum$computername. The output however is appending it to the local path rather than creating the exact URL like so.

function Get-ComputerInfo{

BEGIN {}
PROCESS {

$computername = $_

$ComputerInfo = get-wmiobject win32_operatingsystem -ComputerName $computername | select-object -property @{l='Computer Name' ;e={$_.PSComputerName}}, 
                                                                                                          @{l='Windows Edition' ;e={$_.Caption}},
                                                                                                          @{l='Version' ;e={(Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion').ReleaseId}}, 
                                                                                                          @{l='Build Number' ;e={$_.BuildNumber}},
                                                                                                          @{l='Reporting' ;e={"<a href = 'winservera.adatum/$computername'  > View Report </a>"}} 

$Report = [pscustomobject] $ComputerInfo 


$Report

}

END {}

}

Add-Type -AssemblyName System.Web
$Test = get-content computerlist.txt  | Get-ComputerInfo | ConvertTo-Html -As Table -Head $header 
[System.Web.HttpUtility]::HtmlDecode($Test) | Out-file ComputerList.html
Windows for business Windows Server User experience Other
Windows for business Windows Client for IT Pros User experience Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Oliver Fung 21 Reputation points
    2023-01-11T08:57:32.58+00:00

    Output 2

    output

    So when you click view report of going to URL winservera.adatum/localhost it's going to file:///C:/Users/Administrator/winservera.adatum/localhost

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.