Cara menggunakan convertto-html fragment

Consider you have multiple outputs to display on the webpage using PowerShell and we will use the Convertto-HTML built-in cmdlet for it but to display them properly, we first need to convert each part into fragment using –Fragment parameter.

Show

Let’s just take the simple example without the –Fragment parameter. In the below example, we are going to display the BIOS information, Local disk information, and Automatic but stopped services information.

#To get the BIOS information
Get-CimInstance Win32_BIOS | Select Name, Manufacturer, SerialNumber, Status, Version | ConvertTo-Html | Out-File ComputerInformation.html

#To get the logical disk information
Get-CimInstance Win32_LogicalDisk | where{$_.DriveType -eq '3'} | Select DeviceID, @{N='Total Size(GB)';E={[math]::Round($_.Size/1GB,2)}}, @{N='Free size(GB)';E={[math]::Round($_.Freespace/1GB)}} | ConvertTo-Html| Out-File ComputerInformation.html -Append

#To get the service information
Get-Service | where{($_.StartType -eq "Automatic") -and ($_.Status -eq "Stopped")} | Select Name, DisplayName, StartType, Status | ConvertTo-Html | Out-File ComputerInformation.html -Append

The output of the above script.

Cara menggunakan convertto-html fragment

The output is correct for the above commands but let's check the HTML file by editing it.

Cara menggunakan convertto-html fragment

You can check in the above-mentioned snapshot of the edited HTML file, there are three different HTML files appended into a single file but we don’t need the output in the same format because display might be OK but the background of the HTML edited output file is incorrect. It is also very difficult to link the CSS file to the entire HTML content.

As we need a single HTML file and we will use the –Fragment parameter in Convertto-HTML command, which tells the PowerShell not to create separate HTML for each input. We will check the script below for a better understanding.

$bios = Get-CimInstance Win32_BIOS | Select Name, Manufacturer, SerialNumber, Status, Version | ConvertTo-Html –Fragment

$disks = Get-CimInstance Win32_LogicalDisk | where{$_.DriveType -eq '3'} | Select DeviceID, @{N='Total Size(GB)';E={[math]::Round($_.Size/1GB,2)}}, @{N='Free size(GB)';E={[math]::Round($_.Freespace/1GB)}} | ConvertTo-Html -Fragment

$services = Get-Service | where{($_.StartType -eq "Automatic") -and ($_.Status -eq "Stopped")} | Select Name, DisplayName, StartType, Status | ConvertTo-Html -Fragment

ConvertTo-Html -Body "$bios $disks $services" -Title "Computer Information" | Out-File ComputerInformation.html

When you check the output of the above script, the output will remain the same as earlier mentioned.

Cara menggunakan convertto-html fragment

And now we will check the HTML file by editing it and will check if it has a single HTML file or multiple HTML files appended.

Cara menggunakan convertto-html fragment

There is only one HTML file created and it is easy to attach CSS style to the script. We will modify the script slightly for CSS effects and attach a new CSS file. Both are mentioned below.

PowerShell is a powerful tool that helps you simplify and automate tedious and repetitive tasks. Administrators typically use PowerShell to extract information from a system or database when the data set required has to be presented as a report. But reports in text or CSV files usually lack the flare and fancy styling of HTML. In this tutorial, you will learn how to create nn HTML Report With PowerShell,

Not a reader? Watch this related video tutorial!

Not seeing the video? Make sure your ad blocker is disabled.

PowerShell can help you build HTML reports and get away from these other bland formats. Using just PowerShell, you can make a report come alive with HTML allowing you to make a meaningful presentation of the raw data extracted from the system. You can even apply Cascading Style Sheets (CSS) to easily customize the layout of your report.

In this article, you will learn how to use the

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
6 combined with
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
7 cmdlets to generate an HTML report. You will also learn the basic scripting for CSS and how it can be useful in formatting the design of your HTML based report.

Prerequisites

This article will be a walkthrough. If you intend to follow along, make sure you have the following prerequisites set up ahead of time.

  • All examples will be shown using Windows 10 Build 1709, but this version isn’t required
  • Windows PowerShell 5.1 or later version or PowerShell Core 7
  • Browser like Internet Explorer or Google Chrome

Creating a Basic Computer Information Report using Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html8

To demonstrate how to use the

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
8 cmdlet and its parameters, you will create a script that gets basic information of a machine (such as Operating System, Processor, BIOS, and available Disk space) and generates the information to an HTML report.

You begin with a command that collects information about the operating system version from a machine. Open your PowerShell console then copy and paste the command below then press enter to run the command.

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

When you run the command above, the

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
0 cmdlet collects the properties of the
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
1 class which contains the information about the operating system of the machine, the command will return many results, thus filter is needed to get only the relevant information. The result should look similar to the screenshot shown below.

Cara menggunakan convertto-html fragment
Machine’s Operating System Information

Now that you’ve got the command to return the operating system information, let’s convert the result to HTML code. To convert the result (objects) from the above command in HTML code, you can pipe the output of

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
0 cmdlet to
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
8. Run the command below in your PowerShell console.

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

You can see in the following screenshot below that PowerShell automatically generates the HTML tags from the output of

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
0 cmdlet. The result is displayed in a table format, where the table header shows the property names such as Version, Caption, BuildNumber, and Manufacturer. Each table row represents an object and displays the object’s values for each property.

Cara menggunakan convertto-html fragment
Generated HTML code

Exporting The Report Into HTML File

Now that you’ve got the result and converted to HTML code, let’s export the report to an HTML file using

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
5 cmdlet and view the report in a web browser. Pipe the output of
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
8 cmdlet and specify the path where you want to save the report using
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
7 parameter and use Basic-Computer-Information-Report.html as the name of the file.

Open your PowerShell ISE or any text editor, copy the code below and save the script with the filename 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

Run the Generate-HTML-Report.Ps1 script in your PowerShell Console

.\Generate-HTML-Report.Ps1

After running the script, open the Basic-Computer-Information-Report.html file in a web browser. The web browser interprets the code of the HTML report and displays the data on the browser screen. The report should contain information about the machine’s operating system similar to the screenshot below.

Cara menggunakan convertto-html fragment
HTML report viewed in a web browser

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

At this point, you now have a script that gets information of the machine’s operating system and exports the result to the HTML report. Your goal is to add more commands in the script to get the remaining information of the computer such as Processor, BIOS, Disk, and Services.

Each command will return different computer information formatted as  HTML code. To properly consolidate the information in one single HTML report, use the

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
8 parameter in order to get the table part only of the HTML code generated by
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
8 cmdlet.

As you can see in the screenshot below, PowerShell generates all basic HTML elements when the output is piped to

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

Cara menggunakan convertto-html fragment
List of generated HTML code using
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
8 cmdlet

When you use the

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
8 parameter, PowerShell generates the HTML table element only. The elements
.\Generate-HTML-Report.Ps1
4,
.\Generate-HTML-Report.Ps1
5,
.\Generate-HTML-Report.Ps1
6,
.\Generate-HTML-Report.Ps1
7, and others are omitted.  The result is shown below.

Cara menggunakan convertto-html fragment
List of HTML code for table using Fragment parameter

Now that you already know how the

Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
8 parameter works from the above example, let’s apply that in the script.

The commands in the script below performs the following:

  • The first five lines of commands gets different information from the machine such as Operating System, Processor, BIOS, Disk and Services.
  • Filter the result using
    .\Generate-HTML-Report.Ps1
    9 parameter to display only the relevant values
  • Store the values in respective variables. Each information is formatted as table using
    #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
    0
  • Consolidate the HTML tables using
    #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
    1 parameter into single HTML report
  • Set the title of the report to “Computer Information Report” using
    #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
    2 parameter
  • Export the report as HTML file using
    Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer | ConvertTo-Html | Out-File -FilePath .\Basic-Computer-Information-Report.html
    5 parameter

Additional information about the script is available in the comments in the code snippet below. Update the script with the following code.

#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

Run the script in PowerShell console. You can see the output of the report as shown below.

Cara menggunakan convertto-html fragment
HTML report with basic computer information

Adding Label Using #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.html4 and #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.html5 Parameter

At this point, the script can now get all the basic information of a computer and export the result to HTML. However, as you can see in the above screenshot, someone or a recipient of the report might have difficulty in understanding the content when you remove the annotation as the information is not properly labeled or categorized.

By using the

#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
4 and
#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
5 parameters, you can add labels into each table so anyone can easily discern the content of the report.

The

#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
4 parameter specifies the text to add before the opening
#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
9 tag and the
#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
5 parameter specifies the text to add after the closing
#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

1 tag. Values added on these parameters are not automatically converted to Html code, so you need to explicitly use HTML tags so it will be properly rendered as HTML elements.

Update the script using the commands below then run the script in  PowerShell console.

Below are the changes in the script:

  • New command is added to get the name of the computer. The value of
    #The command below will get the name of the computer
    $ComputerName = "

    Computer name: $env:computername

    " #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 "

    Operating System Information

    " #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 "

    Processor Information

    " #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 "

    BIOS Information

    " #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 "

    Disk Information

    " #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 "

    Services Information

    " #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 "

    Creation Date: $(Get-Date)

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

    2 variable has
    #The command below will get the name of the computer
    $ComputerName = "

    Computer name: $env:computername

    " #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 "

    Operating System Information

    " #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 "

    Processor Information

    " #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 "

    BIOS Information

    " #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 "

    Disk Information

    " #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 "

    Services Information

    " #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 "

    Creation Date: $(Get-Date)

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

    3 tag to change the text format to heading when rendered in a browser.
  • Different labels are added in each table using
    #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
    4 Parameter and values are placed in
    #The command below will get the name of the computer
    $ComputerName = "

    Computer name: $env:computername

    " #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 "

    Operating System Information

    " #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 "

    Processor Information

    " #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 "

    BIOS Information

    " #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 "

    Disk Information

    " #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 "

    Services Information

    " #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 "

    Creation Date: $(Get-Date)

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

    5 tags
  • Creation date label is added at the end of the report using
    #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
    5 Parameter and value is placed in
    #The command below will get the name of the computer
    $ComputerName = "

    Computer name: $env:computername

    " #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 "

    Operating System Information

    " #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 "

    Processor Information

    " #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 "

    BIOS Information

    " #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 "

    Disk Information

    " #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 "

    Services Information

    " #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 "

    Creation Date: $(Get-Date)

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

    7 tag

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

You can see with a little bit of extra work, the report can look a whole lot better, the report should be updated as shown below.

Cara menggunakan convertto-html fragment
HTML report added with labels using PreContent and PostContent Parameters

Changing Table Layout Using #The command below will get the name of the computer $ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

Perhaps, the generated HTML table has multiple columns and you want to change the format to properly display the value as a list, you can use the

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

8 parameter. By default, when you pipe the output to
#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

0, PowerShell generates an HTML table that resembles the Windows PowerShell table format.

As you can see in the screenshot below, the table header displays the property names such as Version, Caption, Build Number and Manufacturer and each table row represents an object and displays the object’s values for each property.

Cara menggunakan convertto-html fragment
HTML code generated by ConvertTo-Html cmdlet formatted as Table

To change the layout of the table to list, use the parameter

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

1 then followed by List. PowerShell generates a two-column HTML table for each object that resembles the Windows PowerShell list format. The first column displays the property names such as Version, Caption, Build Number and Manufacturer and the second column displays the property value.

Cara menggunakan convertto-html fragment
HTML code generated by ConvertTo-Html cmdlet formatted as List

From the above examples, you now have an idea on how to change the layout of the table, let’s apply the

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

8 parameter in our script to change the layout of Operating System, Processor, BIOS and Disk information tables to list format.

Update the script with the following code below. The script has

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

1 parameter in the command lines for Operating System, Processor, BIOS and Disk.

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

After applying the

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

1 parameter, the report should be updated as shown below. The table layouts for Operating System, Processor, BIOS and Disk information are now changed to list.

Cara menggunakan convertto-html fragment
HTML report with tables formatted as List

Enhancing The Report Using CSS

Let’s take the report to the next level and start adding the design using CSS. CSS is used to control how the HTML report will look in a web browser. CSS controls the fonts, text, colors, backgrounds, margins, and layout. At the end of this section, you should be able to see how the report will transform from plain to rich format using CSS.

There are three ways to apply CSS in HTML such as Inline, Internal and External. For this article, you will apply the Internal method using the

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

5 parameter in the HTML report.

The

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

5 parameter specifies the content of the
.\Generate-HTML-Report.Ps1
5 tag. The
.\Generate-HTML-Report.Ps1
5 tag is part of HTML structure where you place the code for CSS. As you can see in the screenshot below the
#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

9 tag is already included when the HTML code is generated by the
Get-CimInstance -Class Win32_OperatingSystem | Select-object Version,Caption,BuildNumber,Manufacturer |  ConvertTo-Html
8 cmdlet.

Cara menggunakan convertto-html fragment
HTML code showing the Head element

Let’s now use CSS to format the HTML report. First, copy the code below and paste it at the beginning of the script. The CSS code assigned in the

$header = @"


@”
1 variable will change the formatting of texts in the report which are placed in
#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

3 tag.

$header = @"


@”

Next, use the

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

5 parameter and assign the
$header = @"


@”
1 variable. Update the script using the code below.

$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" `
-Title "Computer Information" -Head $header -PostContent "

Creation Date: $(Get-Date)

"

When you run the script, the report should be updated as shown below. Notice that the only affected HTML element is the

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

3 which applied to the “Computer name” label. The steps above are a great example of how you can control or manipulate the design of the HTML report using CSS.

Cara menggunakan convertto-html fragment
HTML report with CSS using Head Parameter

To add more design to other tables and labels which are placed in

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

5 tag in the report, continue to update the
$header = @"


@”
1 variable with the CSS code below.

$header = @"

"@

After updating and running the script, the report should be formatted as shown below – Thanks to CSS it is now visually appealing and looks professional.

Cara menggunakan convertto-html fragment
HTML report formatted using CSS

Using HTML Id And Class Attributes In CSS

HTML elements are the building blocks of your entire HTML report, CSS use these elements as a selector to know where the style should be applied. From the previous examples, the CSS code was applied to HTML elements

$header = @"


@”
8,
$header = @"


@”
9, and
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" `
-Title "Computer Information" -Head $header -PostContent "

Creation Date: $(Get-Date)

"

0 in the report. But what if you need to apply different style on different elements? This is where id and class attributes come in. In designing your HTML report, you can use either id or class to define a single element.

Please note that an HTML element can only have one unique id that belongs to that single element, while a class name can be used by multiple elements. For web developers, these attributes are not just for designing the page but primarily being used in scripting to handle how the page will respond to every event or request.

Let’s apply the id and class attributes in the HTML report. As you can see in the code snippet below the creation date label is placed in

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

7 tag.

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

When the report is generated and viewed in the browser, the creation date label is formatted as shown below.

Cara menggunakan convertto-html fragment
HTML report showing the creation date label

To format the creation date label using id attribute – First, assign an id name ‘CreationDate‘ to

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

7 tag. The id name should be placed inside the start tag. The updated code is shown below.

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

Second, create a new CSS code to format the creation date label. Use

$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" `
-Title "Computer Information" -Head $header -PostContent "

Creation Date: $(Get-Date)

"

3 symbol followed by the ID name when declaring an ID in CSS. Add the CSS code below in the
$header = @"


@”
1 variable then save and run the script in the PowerShell console.

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

After assigning the id and creating a new CSS code that targets the id attribute of the

#The command below will get the name of the computer
$ComputerName = "

Computer name: $env:computername

" #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 "

Operating System Information

" #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 "

Processor Information

" #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 "

BIOS Information

" #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 "

Disk Information

" #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 "

Services Information

" #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 "

Creation Date: $(Get-Date)

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

7 tag, the report should be updated as shown below.

Cara menggunakan convertto-html fragment
HTML report showing creation date label formatted using CSS via ID as selector

Let’s apply the class attribute in the Service information table. Using CSS change the color of the text to green **when the value of the state is Running and use red when the value is Stopped.

Cara menggunakan convertto-html fragment
HTML report showing the Services Information table

As previously mentioned, the class attributes can be assigned to multiple HTML elements.  In the HTML report, the element that holds the Running and Stopped text is

$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" `
-Title "Computer Information" -Head $header -PostContent "

Creation Date: $(Get-Date)

"

6 tag. Using
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" `
-Title "Computer Information" -Head $header -PostContent "

Creation Date: $(Get-Date)

"

7 method of PowerShell, assign the class names RunningStatus and StopStatus to all
$Report = ConvertTo-HTML -Body "$ComputerName $OSinfo $ProcessInfo $BiosInfo $DiscInfo $ServicesInfo" `
-Title "Computer Information" -Head $header -PostContent "

Creation Date: $(Get-Date)

"

6 tags within Services information table. Use the commands below and update the script.

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

Add the following CSS code below in the

$header = @"


@”
1 variable. All
tags with a class name of RunningStatus will have the hexadecimal value of
$header = @"

"@
0  which is equivalent to color green,  and All
tags with a class name of StopStatus will have the hexadecimal value of
$header = @"

"@
1  which is equivalent to color red.

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

Save and Run the script. The Service information table in the report should be updated as shown below.

Cara menggunakan convertto-html fragment
HTML report showing the Services Information table formatted using CSS via class selector

Below is the final layout of the HTML report formatted using CSS.

Cara menggunakan convertto-html fragment
Final layout of HTML report

Below are the complete commands for Generate-HTML-Report.Ps1

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

Conclusion

In this article, you’ve learned how to convert the objects (result) to HTML code and generate them to an HTML report.

Generating the report to HTML format gives you the ability to apply CSS that makes the report easier to enhance and manipulate. There are many free online resources that you can use to level up your HTML coding and CSS designing skills.

I hope this article gives you enough ideas on how you can create and improve your HTML report. Cheers!

Further Reading

  • ConvertTo-Html
  • Collecting Information About Computers
  • HTML and CSS

Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.

Explore ATA Guidebooks

More from ATA Learning & Partners

  • Cara menggunakan convertto-html fragment

    Recommended Resources for Training, Information Security, Automation, and more!

  • Cara menggunakan convertto-html fragment

    Get Paid to Write!

    ATA Learning is always seeking instructors of all experience levels. Regardless if you’re a junior admin or system architect, you have something to share. Why not write on a platform with an existing audience and share your knowledge with the world?

  • Cara menggunakan convertto-html fragment

    ATA Learning Guidebooks

    ATA Learning is known for its high-quality written tutorials in the form of blog posts. Support ATA Learning with ATA Guidebook PDF eBooks available offline and with no ads!