Breaking News

Easily generate HTML reports using PowerShell

In the Windows ecosystem, PowerShell has established itself as the essential tool for automation and system management. Among its many capabilities, HTML report generation offers unexpected possibilities for visualizing and sharing technical data. This guide explores how to transform raw data into interactive charts and elegant dashboards in just a few lines of code. ConvertTo-Html: The Native PowerShell Solution The ConvertTo-Html cmdlet is the ideal entry point for converting PowerShell objects to HTML code. Simple yet powerful, it allows you to quickly export system data in a universally accessible format.Basic Export of Running Processes The following command generates an HTML file containing the list of processes: Command Result

Get-Process | ConvertTo-Html | Out-File “Report.html”

📄 Raw HTML file without formatting Advanced customization with CSS To improve readability, you can inject CSS directly into the report:

$Style = “

table { width:100%; border-collapse:collapse }

th { background:#C0C0C0 } td, th { border:1px solid #000; padding:5px }
" Get-Service | ConvertTo-Html -PreContent $Style -Title “Services” | Out-File “Report.html”

https://www.youtube.com/watch?v=jIDKVmHonP0

PSWriteHTML: Professional Reports in a Few Lines

<!– wp:code {"content":"
$Style = "n  table { width:100%; border-collapse:collapse }n  th { background:#C0C0C0 }n  td, th { border:1px solid #000; padding:5px }n"nnGet-Service | ConvertTo-Html -PreContent $Style -Title "Services" | Out-File "Rapport.html"n
“} –>
The
  PSWriteHTML
  module revolutionizes report creation with advanced features:
  📊 Interactive Charts
🔍 Dynamic Filters and Sorts

🎨 Predefined Themes
📑 Multi-Page Structure

Installation and First Steps

Start by installing the module: Install-Module -Name PSWriteHTML -Force A basic report with an interactive table:

  • New-HTML -Title “Report” {
  • New-HTMLTable -DataTable (Get-Process) -HideFooter
  • } -FilePath “Report.html”
  • Use Case: Active Directory Dashboard

Combine the capabilities of PowerShell and PSWriteHTML to create a complete AD monitoring solution:

Component

<!– wp:code {"content":"
Install-Module -Name PSWriteHTML -Forcen
“} –>
Command

Result

<!– wp:code {"content":"
New-HTML -Title "Rapport" {n  New-HTMLTable -DataTable (Get-Process) -HideFootern} -FilePath "Rapport.html"n
“} –>
📊 OS Pie Chart
  New-ChartDonut
Windows Version Visualization

🖥️ Machine List

New-HTMLTable

Interactive Workstation Table 📅 Latest Connections New-HTMLChart
Time Chart Complete Script Example A typical script integrates three phases:
🔍 Data Collection (Get-ADComputer, Get-Service, etc.) 🛠️ Transformation (Select-Object, Group-Object, etc.) 🎨 Report Generation (New-HTML, New-HTMLTable, etc.)
Here’s a significant excerpt: # Chart Section New-HTMLSection -HeaderText “Statistics” {

New-HTMLChart -Title “OS” {

$OSStats | ForEach-Object {

  1. New-ChartDonut -Name $_.Name -Value $_.Count
  2. }
  3. }

}

<!– wp:code {"content":"
# Section graphiquenNew-HTMLSection -HeaderText "Statistiques" {n  New-HTMLChart -Title "OS" {n    $OSStats | ForEach-Object {n      New-ChartDonut -Name $_.Name -Value $_.Countn    }n  }n}n
“} –>
Performance Optimization
For complex reports, here are some best practices:
  ⏱️ Limit data to essential columns
    🧹 Filter upstream (Where-Object)
      💾 Store intermediate results
    🔄 Avoid redundant calls
  
The combination of

PowerShell and HTML

opens up immense possibilities for

  • system administration
  • and
  • data visualization
  • . Whether with native tools or modules like PSWriteHTML, creating professional reports has never been more accessible to IT teams.