How to render clickable link using Powershell
15,129
Solution 1
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 '>','>' -replace '<','<' -replace ''',"'" |
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)
Solution 2
i.e.
$pso = New-Object PSObject -Property @{
SiteUrl = $spweb.url
PageTitle= $PageTitle
PageUrl = "<a href='$PagesUrl'>$PageTitle</a>"
} | ConvertTo-Html
Add-Type -AssemblyName System.Web
[System.Web.HttpUtility]::HtmlDecode($pso) |
Out-File \\myfolder\InventoryReports\$CurrentMonth.html
Comments
-
Nish almost 2 years
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
Thanks in advance
-
Nish about 11 yearswhere should i add this
Add-Type -AssemblyName System.Web [System.Web.HttpUtility]::HtmlDecode($pso)
at the starting of the script ? -
Shay Levy about 11 yearsYes, or just before you first use it.