Private/New-HtmlCleanupReport.ps1

<#
    .SYNOPSIS
    Generates an HTML cleanup report from cleanup result objects.
 
    .DESCRIPTION
    Accepts an array of cleanup result objects and a summary object, then
    generates a styled HTML report suitable for email. All data is passed
    via parameters - no script-scope variable access.
 
    .PARAMETER CleanupResults
    Array of PSCustomObject results returned by New-CleanupReport from each cleanup section.
 
    .PARAMETER Summary
    A PSCustomObject containing overall summary data with properties:
    TotalSeconds, TotalMinutes, SpaceBefore, SpaceAfter, TotalCleaned.
 
    .EXAMPLE
    $Html = New-HtmlCleanupReport -CleanupResults $Results -Summary $Summary
    Generates an HTML report string from the provided cleanup data.
 
    .OUTPUTS
    [string] HTML report body.
 
    .NOTES
    Author: Tom de Leeuw
    Website: https://systom.dev
#>

function New-HtmlCleanupReport {
    [Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Justification = 'Builds an in-memory report; no external state is changed.')]
    [CmdletBinding()]
    [OutputType([string])]
    param(
        [Parameter(Mandatory)]
        [PSCustomObject[]] $CleanupResults,

        [Parameter(Mandatory)]
        [PSCustomObject] $Summary
    )

    process {
        $Date     = Get-Date -Format 'yyyy/MM/dd HH:mm'
        $UserName = [System.Net.WebUtility]::HtmlEncode([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)
        $Server   = [System.Net.WebUtility]::HtmlEncode($env:ComputerName)

        $ScriptSummary = @"
        <table style="width:100%">
            <tr>
                <th>Total run time</th>
                <td>$([System.Net.WebUtility]::HtmlEncode([string]$Summary.TotalSeconds)) / $([System.Net.WebUtility]::HtmlEncode([string]$Summary.TotalMinutes))</td>
            </tr>
            <tr>
                <th>Free space before</th>
                <td>$([System.Net.WebUtility]::HtmlEncode([string]$Summary.SpaceBefore))</td>
            </tr>
            <tr>
                <th>Free space after</th>
                <td>$([System.Net.WebUtility]::HtmlEncode([string]$Summary.SpaceAfter))</td>
            </tr>
            <tr>
                <th>TOTAL space cleaned</th>
                <td>$([System.Net.WebUtility]::HtmlEncode([string]$Summary.TotalCleaned))</td>
            </tr>
        </table>
"@


        [string] $Css = @'
<style>
    html body { font-family: Verdana, Geneva, sans-serif; font-size: 12px; height: 100%; margin: 0; overflow: auto; }
    #header { background: #481818; color: #ffffff; width: 100% }
    #headerTop { padding: 10px; }
    .logo1 { float: left; font-size: 25px; font-weight: bold; padding: 0 7px 0 0; }
    .logo2 { float: left; font-size: 25px; }
    .logo3 { float: right; font-size: 12px; text-align: right; }
    .headerRow1 { background: #481818; height: 5px; }
    .serverRow { background: #000000; color: #ffffff; font-size: 32px; padding: 10px; text-align: center; text-transform: uppercase; }
    .breakdownRow { background: #000000; color: #ffffff; font-size: 32px; padding: 10px; text-align: center; text-transform: uppercase; }
    .sectionRow { background: #481818; color: #ffffff; font-size: 13px; padding: 1px 5px!important; font-weight: bold; height: 15px!important; }
    table { background: #eaebec; border: #cccccc 1px solid; border-collapse: collapse; margin: 0; width: 100%; }
    table th { background: #ededed; border-top: 1px solid #fafafa; border-bottom: 1px solid #e0e0e0; border-left: 1px solid #e0e0e0; height: 45px; min-width: 55px; padding: 0px 15px; text-transform: capitalize; }
    table tr { text-align: center; }
    table td { background: #fafafa; border-top: 1px solid #ffffff; border-bottom: 1px solid #e0e0e0; border-left: 1px solid #e0e0e0; height: 55px; min-width: 55px; padding: 0px 10px; }
    table td:first-child { min-width: 175px; text-align: left; }
    table tr:last-child td { border-bottom: 0; }
    table tr:hover td { background: #f2f2f2; }
    table tr:hover td.sectionRow { background: #481818; }
</style>
'@


        [string] $Body = @"
<div id="header">
    <div id="headerTop">
        <div class="logo1">automaTOM</div>
        <div class="logo2">ComputerCleanup report: $Server</div>
        <div class="logo3">&nbsp;<br/>Generated by $UserName on $Date</div>
        <div style="clear:both;"></div>
    </div>
    <div style="clear:both;"></div>
</div>
<div class="headerRow1"></div>
<div class="serverRow">SUMMARY</div>
<div class="headerRow1"></div>
<div class="headerRow1"></div>
<div>$ScriptSummary</div>
<div class="headerRow1"></div>
<div class="breakdownRow">SECTION BREAKDOWN</div>
"@


        $CleanupResults | ConvertTo-Html -Head $Css -Body $Body | Out-String
    }
}