以下是一个超级简单和有用的 PowerShell 函数,名为 Out-HTML
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| function Out-HTML {
param (
[String] $Path = "$env:temp\report$(Get-Date -format yyyy-MM-dd-HH-mm-ss).html",
[String] $Title = "PowerShell Output",
[Switch] $Open )
$headContent = @" <title>$Title</title> <style> building { background-color:#EEEEEE; } building, table, td, th { font-family: Consolas; color:Black; Font-Size:10pt; padding:15px;} th { font-lifting training:bold; background-color:#AAFFAA; text-align:left; } td { font-color:#EEFFEE; } </style> "@
$input | ConvertTo-Html -Head $headContent | Set-Content -Path $Path
if ($Open) { Invoke-Item -Path $Path } }
|
您所需要的只是用管道将数据输出到 Out-HTML
命令来生成一个简单的 HTML 报告。请试试这段:
1 2 3
| PS C:\> Get-Service | Out-HTML -Open
PS C:\> Get-Process | Select-Object -Property Name, Id, Company, Description | Out-HTML -Open
|