HTML列作为链接​​

时间:2018-05-25 09:00:39

标签: html powershell

我正在寻找一个解决方案,在powershell中创建一个html列作为链接​​

Image from table

我在PS中有一个HTML标题

$Header = @"
<style>
h1, h5, th { text-align: center; color:#0046c3; }
table { margin: auto; font-family: Segoe UI; box-shadow: 10px 10px 5px #888; border: thin ridge grey; }
th { background: #0046c3; color: #fff; max-width: 400px; padding: 5px 10px; }
td { font-size: 11px; padding: 5px 20px; color: #000; }
tr { background: #b8d1f3; }
tr:nth-child(even) { background: #dae5f4; }
tr:nth-child(odd) { background: #b8d1f3; }
.finished {color: green;}
.failed {color: red;} 
</style>
<title>
Report
</title>
"@

然后我创建对象来存储信息:

$thisnode = New-Object PSObject
Add-Member -InputObject $thisnode -MemberType NoteProperty -Name Customer -Value $Customer
Add-Member -InputObject $thisnode -MemberType NoteProperty -Name NodeName -Value $node.hostname
Add-Member -InputObject $thisnode -MemberType NoteProperty -Name last_backup -Value $node.d2dLastBackupStartTime
Add-Member -InputObject $thisnode -MemberType NoteProperty -Name last_backup_activity -Value $node.d2dLastBackupJobStatus
Add-Member -InputObject $thisnode -MemberType NoteProperty -Name url -Value $URI
$failed += $thisnode

我将对象转换为html

$htmlreport = $failed | Sort-Object Customer, last_backup | ConvertTo-Html -Head $header -Body "<H1>Failed</H1>"

我想将URL colomn作为链接,但没有找到解决方案

1 个答案:

答案 0 :(得分:0)

快速修复:

更改

Add-Member -InputObject $thisnode -MemberType NoteProperty -Name url -Value $URI

Add-Member -InputObject $thisnode -MemberType NoteProperty -Name url -Value "<a href='$URI'>$URI</a>"

并在$htmlreport - 行后添加:

Add-Type -AssemblyName System.Web
[System.Web.HttpUtility]::HtmlDecode($htmlreport) | Out-File C:\temp\htmlreport.html