Private/New-HtmlDashboard.ps1
|
function New-HtmlDashboard { <# .SYNOPSIS Generates a dark-themed HTML dashboard for the Linux server inventory. #> [CmdletBinding()] param( [Parameter(Mandatory)] [array]$ServerData, [string]$OrganizationalUnit = 'OU=Linux Servers' ) $totalCount = @($ServerData).Count $onlineCount = @($ServerData | Where-Object { $_.Online -eq $true }).Count $offlineCount = @($ServerData | Where-Object { $_.Online -eq $false }).Count $unknownCount = @($ServerData | Where-Object { $_.Online -eq $null -or $_.Online -eq 'N/A' }).Count $onlineClass = if ($onlineCount -gt 0) { 'clean' } else { '' } $offlineClass = if ($offlineCount -gt 0) { 'findings' } else { 'clean' } # Build table rows $tableRows = ($ServerData | ForEach-Object { $statusClass = switch ($_.Online) { $true { 'finding-ok' } $false { 'finding-bad' } default { '' } } $statusText = switch ($_.Online) { $true { 'Online' } $false { 'Offline' } default { 'Unknown' } } $managedBy = if ($_.ManagedBy) { $_.ManagedBy } else { '—' } $desc = if ($_.Description) { $_.Description } else { '—' } $osVer = if ($_.OperatingSystemVersion) { $_.OperatingSystemVersion } else { '—' } "<tr><td>$($_.Name)</td><td>$($_.IPv4Address)</td><td>$($_.OperatingSystem)</td><td>$osVer</td><td>$desc</td><td>$managedBy</td><td class=`"$statusClass`">$statusText</td></tr>" }) -join "`n " @" <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Linux Server Inventory</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Segoe UI', Tahoma, sans-serif; background: #0d1117; color: #c9d1d9; padding: 2rem; } .header { background: linear-gradient(135deg, #1a1f2e 0%, #2a1a0a 100%); padding: 2rem; border-radius: 8px; margin-bottom: 2rem; } .header h1 { color: #d29922; font-size: 1.8rem; margin-bottom: 0.5rem; } .header .meta { color: #8b949e; font-size: 0.9rem; } .summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 2rem; } .card { background: #161b22; border: 1px solid #30363d; border-radius: 8px; padding: 1.5rem; text-align: center; } .card .number { font-size: 2.5rem; font-weight: 700; } .card .label { color: #8b949e; font-size: 0.85rem; margin-top: 0.5rem; } .card.findings .number { color: #f85149; } .card.clean .number { color: #3fb950; } .card.total .number { color: #d29922; } .section { background: #161b22; border: 1px solid #30363d; border-radius: 8px; margin-bottom: 1.5rem; padding: 1.5rem; } .section h2 { color: #d29922; font-size: 1.3rem; margin-bottom: 0.5rem; } .section .summary { color: #8b949e; margin-bottom: 1rem; font-size: 0.9rem; } .table-wrapper { overflow-x: auto; } table { width: 100%; border-collapse: collapse; font-size: 0.85rem; } th { background: #21262d; color: #d29922; padding: 0.75rem; text-align: left; border-bottom: 2px solid #30363d; white-space: nowrap; } td { padding: 0.6rem 0.75rem; border-bottom: 1px solid #21262d; } tr:hover { background: #1c2128; } .finding-bad { color: #f85149; font-weight: 600; } .finding-ok { color: #3fb950; } .footer { text-align: center; color: #484f58; margin-top: 2rem; font-size: 0.8rem; } </style> </head> <body> <div class="header"> <h1>Linux Server Inventory</h1> <div class="meta">Generated $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') | OU: $OrganizationalUnit | AD-LinuxInventory v1.0.0</div> </div> <div class="summary-cards"> <div class="card total"> <div class="number">$totalCount</div> <div class="label">Total Servers</div> </div> <div class="card $onlineClass"> <div class="number">$onlineCount</div> <div class="label">Online</div> </div> <div class="card $offlineClass"> <div class="number">$offlineCount</div> <div class="label">Offline</div> </div> <div class="card"> <div class="number">$unknownCount</div> <div class="label">Unknown</div> </div> </div> <div class="section"> <h2>Registered Linux Servers</h2> <p class="summary">$totalCount servers registered in Active Directory</p> <div class="table-wrapper"> <table> <thead> <tr> <th>Name</th><th>IP Address</th><th>Operating System</th><th>OS Version</th><th>Description</th><th>Managed By</th><th>Status</th> </tr> </thead> <tbody> $tableRows </tbody> </table> </div> </div> <div class="footer"> Generated by AD-LinuxInventory | github.com/larro1991/AD-LinuxInventory </div> </body> </html> "@ } |