Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to render clickable link using Powershell

I am using below powershell script to write the output to a html file, the issue is its rendering everything as text.

My code:

$PagesObject = New-Object PSObject
Add-Member -input $PagesObject noteproperty 'Site Url' $spweb.url
Add-Member -input $PagesObject noteproperty 'Page Title' $PageTitle
Add-Member -input $PagesObject noteproperty 'Page Url' "<a href="$PagesUrl">$PageTitle</a>"     
$results += $PagesObject
$results | ConvertTo-HTML -head  $a  -body | Out-File \\myfolder\InventoryReports\$CurrentMonth.html

I want to render it as clickable link

check below screenshot to see how it is rendering now enter image description here

Thanks in advance

like image 252
Nish Avatar asked Jan 14 '23 20:01

Nish


1 Answers

PowerShell encodes special characters. One way to solve this would be to convert them back and then write the result ot a file:

$pso = New-Object PSObject -Property @{
    SiteUrl = $spweb.url
    PageTitle= $PageTitle
    PageUrl = "<a href='$PagesUrl'>$PageTitle</a>"  
} | ConvertTo-Html


$pso -replace '&gt;','>' -replace '&lt;','<' -replace '&#39;',"'" | 
Out-File \\myfolder\InventoryReports\$CurrentMonth.html

UPDATE:

Here's a better way that will take care of all html entities:

Add-Type -AssemblyName System.Web
[System.Web.HttpUtility]::HtmlDecode($pso)
like image 62
Shay Levy Avatar answered Jan 29 '23 07:01

Shay Levy