powershell - 如何使用 Powershell 呈现可点击的链接

标签 powershell powershell-2.0 powershell-ise

我正在使用下面的 powershell 脚本将输出写入 html 文件,问题是它将所有内容都呈现为文本。

我的代码:

$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

我想将其呈现为可点击链接

检查下面的屏幕截图,看看它现在是如何渲染的
enter image description here

提前致谢

最佳答案

PowerShell 对特殊字符进行编码。解决此问题的一种方法是将它们转换回来,然后将结果写入文件:

$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

更新:

这是处理所有 html 实体的更好方法:
Add-Type -AssemblyName System.Web
[System.Web.HttpUtility]::HtmlDecode($pso)

关于powershell - 如何使用 Powershell 呈现可点击的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15581012/

相关文章:

powershell - 如何使Powershell-ISE释放Cmdlet DLL

azure - 获取过去 30 天内的最后一次登录,Get-MgAuditLogSignIn - PowerShell

Powershell 阻止 UTF8 转换

powershell - 在配置文件中有条件地加载管理单元

powershell - 从PowerShell中的后台作业中调用的函数获取返回值

powershell - Powershell脚本可以保存VirtualBox VM的状态,但每次都会出错

powershell - 通过Powershell向Asana添加数据

powershell - 根据 powershell 中另一个参数的值设置 [Parameter (mandatory = $true/$false)]

powershell - 对Hashtable排序并将其分配给Powershell中的新变量

powershell - 从 Powershell 中的对象数组中删除项目