- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to generate multiple reports in HTML using PowerShell?
To generate or append multiple outputs in the HTML file using PowerShell, we need to use the - Fragment parameter in the ConvertTo-HTML command.
For example, let say we need to generate the computer utilization report which includes the top 5 consuming processes, stopped services, and the disk utilization report. A single report can be generated by sending the output to the ConvertTo-HTML pipeline command.
Example
$Heading = "<h1><center>System Utilization Report</h1></center>" $procs = Get-Process | Sort-Object -Property CPU -Descending| Select - First 5 | ` ConvertTo-Html -Property ProcessName, ID, CPU -Fragment - PreContent "<h3>High Utilization Processes</h3>" $services = Get-Service | where{$_.StartType -eq "Disabled"} | ` ConvertTo-Html -Property Name, Status, StartType -Fragment - PreContent "<h3>Disabled Services</h3>" $disks = Get-WmiObject win32_logicaldisk | ` Select DeviceID, @{N='FreeSpace(GB)';E={[math]::Round(($_.FreeSpace/1GB),2)}} , ` @{N='TotalSpace(GB)';E={[math]::Round(($_.Size/1GB),2)}} | ` ConvertTo-Html -Fragment -PreContent "<h3>Disk Information</h3>" ConvertTo-Html -Body "$Heading $procs $services $disks" | OutFile C:\Temp\SystemUtilizationReport.html ii C:\Temp\SystemUtilizationReport.html
Output
To add the CSS style to the Report,
$Heading = "<h1><center>System Utilization Report</h1></center>" $procs = Get-Process | Sort-Object -Property CPU -Descending| Select - First 5 | ` ConvertTo-Html -Property ProcessName, ID, CPU -Fragment - PreContent "<h3>High Utilization Processes</h3>" $services = Get-Service | where{$_.StartType -eq "Disabled"} | ` ConvertTo-Html -Property Name, Status, StartType -Fragment - PreContent "<h3>Disabled Services</h3>" $disks = Get-WmiObject win32_logicaldisk | ` Select DeviceID, @{N='FreeSpace(GB)';E={[math]::Round(($_.FreeSpace/1GB),2)}} , ` @{N='TotalSpace(GB)';E={[math]::Round(($_.Size/1GB),2)}} | ` ConvertTo-Html -Fragment -PreContent "<h3>Disk Information</h3>" ConvertTo-Html -Body "$Heading $procs $services $disks" -Head $cssstyle | OutFile C:\Temp\SystemUtilizationReport.html ii C:\Temp\SystemUtilizationReport.html
Output
- Related Articles
- How to generate an HTML report using PowerShell?
- How to Generate Newman Reports on Jenkins using Postman?
- How to display multiple outputs on an HTML webpage using PowerShell?
- How to generate a strong password using PowerShell?
- How to stop multiple services using PowerShell?
- How to start multiple windows services using PowerShell?
- How to copy multiple files in PowerShell using Copy-Item?
- How to add multiple values in the Hashtable using PowerShell?
- How to generate multiple insert queries via java?
- In SAP Crystal Reports XI, return records that match multiple conditions
- How to use multiple attribute in HTML?
- How to use CSS style in PowerShell HTML Output?
- How to get services based on multiple conditional parameters in PowerShell?
- Using Filter to fetch specific data in SAP Crystal Reports
- How to traceroute using PowerShell?

Advertisements