当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

作者:精品下载站 日期:2024-12-14 13:01:18 浏览:14 分类:玩电脑

如何使用 PowerShell 创建 HTML 报告


PowerShell 是一个功能强大的工具,可帮助您简化和自动化繁琐且重复的任务。当所需的数据集必须以报告形式呈现时,管理员通常使用 PowerShell 从系统或数据库中提取信息。但文本或 CSV 文件格式的报告通常缺乏 HTML 的耀眼和花哨的样式。在本教程中,您将学习如何使用 PowerShell 创建 nn HTML 报告,

PowerShell 可以帮助您构建 HTML 报告并摆脱这些其他乏味的格式。仅使用 PowerShell,您就可以使用 HTML 生成生动的报告,从而能够对从系统中提取的原始数据进行有意义的演示。您甚至可以应用层叠样式表(CSS)来轻松自定义报告的布局。

在本文中,您将了解如何将 ConvertTo-HTMLOut-file cmdlet 结合使用来生成 HTML 报告。您还将学习 CSS 的基本脚本以及它如何在格式化基于 HTML 的报告设计时发挥作用。

先决条件

本文将是一个演练。如果您打算继续操作,请确保提前设置以下先决条件。

  • 所有示例都将使用 Windows 10 Build 1709 显示,但不需要此版本
  • Windows PowerShell 5.1 或更高版本或 PowerShell Core 7
  • Internet Explorer 或 Google Chrome 等浏览器

使用 ConvertTo-Html 创建基本计算机信息报告

为了演示如何使用 ConvertTo-Html cmdlet 及其参数,您将创建一个脚本来获取计算机的基本信息(例如操作系统、处理器、BIOS 和可用磁盘空间)并生成HTML 报告中的信息。

您首先使用从计算机收集有关操作系统版本信息的命令。打开 PowerShell 控制台,然后复制并粘贴下面的命令,然后按 Enter 运行该命令。

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer

当您运行上面的命令时,Get-CimInstance cmdlet 会收集 Win32_OperatingSystem 类的属性,其中包含有关计算机操作系统的信息,该命令将返回许多结果,因此需要过滤以仅获取相关信息。结果应该类似于下面显示的屏幕截图。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

现在您已经获得了返回操作系统信息的命令,让我们将结果转换为 HTML 代码。要将上述命令的结果(对象)转换为 HTML 代码,您可以将 Get-CimInstance cmdlet 的输出通过管道传输到 ConvertTo-Html。在 PowerShell 控制台中运行以下命令。

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html

您可以在下面的屏幕截图中看到,PowerShell 自动从 Get-CimInstance cmdlet 的输出生成 HTML 标记。结果以表格格式显示,其中表格标题显示属性名称,例如 VersionCaptionBuildNumber 和 制造商。。每个表行代表一个对象并显示该对象的每个属性的值。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

将报告导出为 HTML 文件

现在您已获得结果并转换为 HTML 代码,让我们使用 Out-file cmdlet 将报告导出到 HTML 文件,并在 Web 浏览器中查看报告。通过管道传输 ConvertTo-Html cmdlet 的输出,并使用 -FilePath 参数指定要保存报告的路径,并使用Basic-Computer-Information-Report。 html 作为文件名。

打开 PowerShell ISE 或任何文本编辑器,复制下面的代码并使用文件名 Generate-HTML-Report.Ps1 保存脚本

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html

在 PowerShell 控制台中运行 Generate-HTML-Report.Ps1 脚本

.\Generate-HTML-Report.Ps1

运行脚本后,在 Web 浏览器中打开 Basic-Computer-Information-Report.html 文件。 Web 浏览器解释 HTML 报告的代码并将数据显示在浏览器屏幕上。该报告应包含有关计算机操作系统的信息,类似于下面的屏幕截图。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

使用 Fragment 参数组合报告

现在,您已经有了一个脚本,可以获取计算机操作系统的信息并将结果导出到 HTML 报告。您的目标是在脚本中添加更多命令以获取计算机的剩余信息,例如处理器、BIOS、磁盘和服务。

每个命令都会返回不同的计算机信息,格式为 HTML 代码。要正确地将信息合并到一个 HTML 报告中,请使用 Fragment 参数,以便仅获取由 ConvertTo-Html cmdlet 生成的 HTML 代码的表格部分。

正如您在下面的屏幕截图中看到的,当输出通过管道传输到 ConvertTo-Html cmdlet 时,PowerShell 会生成所有基本 HTML 元素。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

当您使用 Fragment 参数时,PowerShell 仅生成 HTML 表格元素。元素 和其他元素被省略。结果如下所示。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

现在您已经了解了上面示例中的 Fragment 参数的工作原理,让我们在脚本中应用它。

下面脚本中的命令执行以下操作:

  • 前五行命令从机器获取不同的信息,例如操作系统、处理器、BIOS、磁盘和服务。
  • 使用 -Property 参数过滤结果以仅显示相关值
  • 将值存储在各个变量中。每个信息都使用 -Fragment 格式化为表格
  • 使用 -Body 参数将 HTML 表格合并到单个 HTML 报告中
  • 使用 -Title 参数将报告标题设置为“计算机信息报告”
  • 使用 Out-file 参数将报告导出为 HTML 文件

有关该脚本的其他信息可在下面代码片段的注释中找到。使用以下代码更新脚本。

#The command below will get the Operating System information, convert the result to HTML code as a table and store it to a variable
$OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment

#The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
$ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment

#The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
$BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment

#The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
$DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment

#The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
$ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  |ConvertTo-Html -Property Name,DisplayName,State -Fragment
 
#The command below will combine all the information gathered into a single HTML report
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" 

#The command below will generate the report to an HTML file
$Report | Out-File .\Basic-Computer-Information-Report.html

在 PowerShell 控制台中运行脚本。您可以看到报告的输出,如下所示。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

使用 PreContentPostContent 参数添加标签

此时,脚本现在可以获取计算机的所有基本信息并将结果导出为 HTML。但是,正如您在上面的屏幕截图中看到的,当您删除注释时,报告的某人或收件人可能难以理解内容,因为信息没有正确标记或分类。

通过使用 PreContentPostContent 参数,您可以在每个表中添加标签,以便任何人都可以轻松辨别报告的内容。

PreContent 参数指定要在开始 标记之前添加的文本,PostContent 参数指定要在结束 标记之后添加的文本> 标签。添加到这些参数上的值不会自动转换为 Html 代码,因此您需要显式使用 HTML 标记,以便将其正确呈现为 HTML 元素。

使用以下命令更新脚本,然后在 PowerShell 控制台中运行该脚本。

以下是脚本中的更改:

  • 添加新命令来获取计算机的名称。 $ComputerName 变量的值具有 <h1> 标记,用于在浏览器中呈现时将文本格式更改为标题。
  • 使用 PreContent 参数在每个表中添加不同的标签,并将值放置在 <h2> 标签中
  • 使用 PostContent 参数将创建日期标签添加到报告末尾,并将值放置在 <p> 标记中
#The command below will get the name of the computer
$ComputerName = "<h1>Computer name: $env:computername</h1>"

#The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable
$OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "<h2>Operating System Information</h2>"

#The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
$ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "<h2>Processor Information</h2>"

#The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
$BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "<h2>BIOS Information</h2>"

#The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
$DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "<h2>Disk Information</h2>"

#The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
$ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "<h2>Services Information</h2>"

#The command below will combine all the information gathered into a single HTML report
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "<p>Creation Date: $(Get-Date)<p>"

#The command below will generate the report to an HTML file
$Report | Out-File .\Basic-Computer-Information-Report.html

您可以看到,通过一些额外的工作,报告可以看起来更好,报告应该更新如下所示。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

使用 As 参数更改表格布局

也许,生成的 HTML 表格有多列,并且您想要更改格式以将值正确显示为列表,您可以使用 As 参数。默认情况下,当您通过管道将输出传送到 ConvertTo-html 时,PowerShell 会生成一个类似于 Windows PowerShell 表格式的 HTML 表。

正如您在下面的屏幕截图中看到的,表格标题显示属性名称,例如 VersionCaptionBuild NumberManufacturer 并且每个表行代表一个对象并显示该对象的每个属性的值。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

要将表格布局更改为列表,请使用参数-As,然后使用List。 PowerShell 为每个对象生成一个类似于 Windows PowerShell 列表格式的两列 HTML 表。第一列显示属性名称,例如 VersionCaptionBuild NumberManufacturer,第二列显示财产价值。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

通过上面的示例,您现在已经了解了如何更改表的布局,让我们在脚本中应用 As 参数来更改操作系统、处理器、BIOS 和磁盘信息表的布局为列表格式。

使用下面的代码更新脚本。该脚本在操作系统、处理器、BIOS 和磁盘的命令行中具有 -As 参数。

#The command below will get the name of the computer
$ComputerName = "<h1>Computer name: $env:computername</h1>"

#The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable
$OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -As List -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "<h2>Operating System Information</h2>"

#The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
$ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -As List -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "<h2>Processor Information</h2>"

#The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
$BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -As List -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "<h2>BIOS Information</h2>"

#The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
$DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -As List -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "<h2>Disk Information</h2>"

#The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
$ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  |ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "<h2>Services Information</h2>"
  
#The command below will combine all the information gathered into a single HTML report
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Title "Computer Information Report" -PostContent "<p>Creation Date: $(Get-Date)<p>"

#The command below will generate the report to an HTML file
$Report | Out-File .\Basic-Computer-Information-Report.html

应用 -As 参数后,报告应更新,如下所示。操作系统、处理器、BIOS 和磁盘信息的表格布局现已更改为列表。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

使用 CSS 增强报告

让我们将报告提升到一个新的水平,并开始使用 CSS 添加设计。 CSS 用于控制 HTML 报告在 Web 浏览器中的外观。 CSS 控制字体、文本、颜色、背景、边距和布局。在本节结束时,您应该能够看到如何使用 CSS 将报告从简单格式转换为丰富格式。

在HTML中应用CSS有三种方式,例如内联、内部和外部。对于本文,您将使用 HTML 报告中的 Header 参数来应用内部方法。

Header 参数指定 标记的内容。 标签是 HTML 结构的一部分,您可以在其中放置 CSS 代码。正如您在下面的屏幕截图中看到的,当 ConvertTo-Html cmdlet 生成 HTML 代码时,已包含 <head> 标记。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

现在让我们使用 CSS 来格式化 HTML 报告。首先,复制下面的代码并将其粘贴到脚本的开头。 $header 变量中分配的 CSS 代码将更改报告中放置在 <h1> 标记中的文本的格式。

$header = @"
<style>

    h1 {

        font-family: Arial, Helvetica, sans-serif;
        color: #e68a00;
        font-size: 28px;

    } 
</style>

@”

接下来,使用 Header 参数并分配 $header 变量。使用下面的代码更新脚本。

$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" `
-Title "Computer Information" -Head $header -PostContent "<p>Creation Date: $(Get-Date)<p>"

运行脚本时,报告应更新,如下所示。请注意,唯一受影响的 HTML 元素是应用于“计算机名称”标签的 <h1>。上述步骤是一个很好的示例,说明如何使用 CSS 控制或操作 HTML 报告的设计。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

要向报表中放置在 <h2> 标记中的其他表格和标签添加更多设计,请继续使用下面的 CSS 代码更新 $header 变量。

$header = @"
<style>

    h1 {

        font-family: Arial, Helvetica, sans-serif;
        color: #e68a00;
        font-size: 28px;

    }

    
    h2 {

        font-family: Arial, Helvetica, sans-serif;
        color: #000099;
        font-size: 16px;

    }

    
    
   table {
		font-size: 12px;
		border: 0px; 
		font-family: Arial, Helvetica, sans-serif;
	} 
	
    td {
		padding: 4px;
		margin: 0px;
		border: 0;
	}
	
    th {
        background: #395870;
        background: linear-gradient(#49708f, #293f50);
        color: #fff;
        font-size: 11px;
        text-transform: uppercase;
        padding: 10px 15px;
        vertical-align: middle;
	}

    tbody tr:nth-child(even) {
        background: #f0f0f2;
    }

        #CreationDate {

        font-family: Arial, Helvetica, sans-serif;
        color: #ff3300;
        font-size: 12px;

    }
    



</style>
"@

更新并运行脚本后,报告的格式应如下所示 - 感谢 CSS,它现在在视觉上很有吸引力并且看起来很专业。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

在 CSS 中使用 HTML Id 和 Class 属性

HTML 元素是整个 HTML 报告的构建块,CSS 使用这些元素作为选择器来了解应在何处应用样式。在前面的示例中,CSS 代码应用于报表中的 HTML 元素 h1h2table。但是如果您需要在不同的元素上应用不同的样式怎么办?这就是 id 和 class 属性的用武之地。在设计 HTML 报告时,您可以使用 id 或 class 来定义单个元素。

请注意,一个 HTML 元素只能有一个属于该单个元素的唯一 ID,而类名可以由多个元素使用。对于 Web 开发人员来说,这些属性不仅仅用于设计页面,而且主要用于编写脚本来处理页面如何响应每个事件或请求。

让我们在 HTML 报告中应用 id 和 class 属性。正如您在下面的代码片段中看到的,创建日期标签放置在 <p> 标记中。

-PostContent "<p>Creation Date: $(Get-Date)</p>"

生成报告并在浏览器中查看时,创建日期标签的格式如下所示。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

要使用 id 属性格式化创建日期标签 - 首先,为 <p> 标记分配一个 id 名称“CreationDate”。 id 名称应放置在开始标记内。更新后的代码如下所示。

-PostContent "<p id='CreationDate'>Creation Date: $(Get-Date)</p>"

其次,创建一个新的 CSS 代码来格式化创建日期标签。在 CSS 中声明 ID 时,请使用 # 符号后跟 ID 名称。在 $header 变量中添加以下 CSS 代码,然后在 PowerShell 控制台中保存并运行该脚本。

#CreationDate {
    font-family: Arial, Helvetica, sans-serif;
    color: #ff3300;
    font-size: 12px;
}

分配 id 并创建针对 <p> 标记的 id 属性的新 CSS 代码后,报告应更新,如下所示。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

让我们在服务信息表中应用类属性。当状态值为 Running 时,使用 CSS 将文本颜色更改为绿色 **;当状态值为 Stopped 时,使用红色。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

如前所述,类属性可以分配给多个 HTML 元素。在 HTML 报告中,保存 RunningStopped 文本的元素是 <td> 标记。使用 PowerShell 的 -Replace 方法,将类名 RunningStatusStopStatus 分配给 <td> 标记em>服务信息表。使用以下命令并更新脚本。

$ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  | ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "<h2>Services Information</h2>"
$ServicesInfo = $ServicesInfo -replace '<td>Running</td>','<td>Running</td>' 
$ServicesInfo = $ServicesInfo -replace '<td>Stopped</td>','<td>Stopped</td>'

在下面的 $header 变量中添加以下 CSS 代码。所有类名为 RunningStatus 的 标记都将具有十六进制值 #008000 ,相当于绿色,并且所有类名为 StopStatus 的 标记都将具有十六进制值#ff0000 相当于红色。

.RunningStatus {
    color: #008000;
}

.StopStatus {
    color: #ff0000;
}

保存并运行脚本。报告中的服务信息表应更新,如下所示。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

下面是使用 CSS 格式化的 HTML 报告的最终布局。

[玩转系统] 如何使用 PowerShell 创建 HTML 报告

以下是 Generate-HTML-Report.Ps1 的完整命令

#CSS codes
$header = @"
<style>

    h1 {

        font-family: Arial, Helvetica, sans-serif;
        color: #e68a00;
        font-size: 28px;

    }

    
    h2 {

        font-family: Arial, Helvetica, sans-serif;
        color: #000099;
        font-size: 16px;

    }

    
    
   table {
		font-size: 12px;
		border: 0px; 
		font-family: Arial, Helvetica, sans-serif;
	} 
	
    td {
		padding: 4px;
		margin: 0px;
		border: 0;
	}
	
    th {
        background: #395870;
        background: linear-gradient(#49708f, #293f50);
        color: #fff;
        font-size: 11px;
        text-transform: uppercase;
        padding: 10px 15px;
        vertical-align: middle;
	}

    tbody tr:nth-child(even) {
        background: #f0f0f2;
    }
    


    #CreationDate {

        font-family: Arial, Helvetica, sans-serif;
        color: #ff3300;
        font-size: 12px;

    }



    .StopStatus {

        color: #ff0000;
    }
    
  
    .RunningStatus {

        color: #008000;
    }




</style>
"@

#The command below will get the name of the computer
$ComputerName = "<h1>Computer name: $env:computername</h1>"

#The command below will get the Operating System information, convert the result to HTML code as table and store it to a variable
$OSinfo = Get-CimInstance -Class Win32_OperatingSystem | ConvertTo-Html -As List -Property Version,Caption,BuildNumber,Manufacturer -Fragment -PreContent "<h2>Operating System Information</h2>"

#The command below will get the Processor information, convert the result to HTML code as table and store it to a variable
$ProcessInfo = Get-CimInstance -ClassName Win32_Processor | ConvertTo-Html -As List -Property DeviceID,Name,Caption,MaxClockSpeed,SocketDesignation,Manufacturer -Fragment -PreContent "<h2>Processor Information</h2>"

#The command below will get the BIOS information, convert the result to HTML code as table and store it to a variable
$BiosInfo = Get-CimInstance -ClassName Win32_BIOS | ConvertTo-Html -As List -Property SMBIOSBIOSVersion,Manufacturer,Name,SerialNumber -Fragment -PreContent "<h2>BIOS Information</h2>"

#The command below will get the details of Disk, convert the result to HTML code as table and store it to a variable
$DiscInfo = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DriveType=3" | ConvertTo-Html -As List -Property DeviceID,DriveType,ProviderName,VolumeName,Size,FreeSpace -Fragment -PreContent "<h2>Disk Information</h2>"

#The command below will get first 10 services information, convert the result to HTML code as table and store it to a variable
$ServicesInfo = Get-CimInstance -ClassName Win32_Service | Select-Object -First 10  |ConvertTo-Html -Property Name,DisplayName,State -Fragment -PreContent "<h2>Services Information</h2>"
$ServicesInfo = $ServicesInfo -replace '<td>Running</td>','<td>Running</td>'
$ServicesInfo = $ServicesInfo -replace '<td>Stopped</td>','<td>Stopped</td>'

  
#The command below will combine all the information gathered into a single HTML report
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" -Head $header -Title "Computer Information Report" -PostContent "<p id='CreationDate'>Creation Date: $(Get-Date)</p>"

#The command below will generate the report to an HTML file
$Report | Out-File .\Basic-Computer-Information-Report.html

结论

在本文中,您学习了如何将对象(结果)转换为 HTML 代码并将其生成为 HTML 报告。

将报告生成为 HTML 格式使您能够应用 CSS,从而使报告更易于增强和操作。您可以使用许多免费的在线资源来提高您的 HTML 编码和 CSS 设计技能。

我希望本文能够为您提供有关如何创建和改进 HTML 报告的足够想法。干杯!

进一步阅读

  • 转换为 Html
  • 收集有关计算机的信息
  • HTML 和 CSS

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯