如何在SCCM软件中心预扫描HTML报告顶部添加状态列值的统计计数
Got it, let's tackle adding that state count summary to your HTML report! Here's how you can modify your existing PowerShell script to include the stats section at the top, plus a quick fix for a styling typo I noticed:
Modified PowerShell Script
# Fixed the typo in background-color (original had "backgroud-color") $Style = @" <Style> BODY{font-family:Calibri;font-size:12pt;} TABLE{border-width: 1px;border-style:solid;border-color: black;border-collapse;padding-right:5px;} TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;color:black;background-color:#34baed;} TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;} </Style> "@ $Output = Import-Csv ".\Servers.csv" # 1. Calculate state counts, normalize WMI Error entries $StateStats = $Output | Group-Object -Property State | Select-Object ` @{Name='State'; Expression={ # Standardize "Error connecting server: WMI Error" to just "WMI Error" if ($_.Name -match "WMI Error") { "WMI Error" } else { $_.Name } }}, @{Name='Count'; Expression={$_.Count}} | Sort-Object State # 2. Convert stats to a standalone HTML table fragment $StatsTableHtml = $StateStats | ConvertTo-HTML -Fragment -Property State, Count # 3. Calculate total unique servers (fixes missing $TotalServers variable) $TotalServers = ($Output.ServerName | Select-Object -Unique).Count # 4. Build the full HTML report with stats at the top $HTMLData = $Output | Select ServerName, LastBootedon, ArticleId, Patch, State $Email = $HTMLData | ConvertTo-HTML -Body @" <H2>SCCM Software Center Pre Scan Report</H2> <h3>State Count Summary</h3> $StatsTableHtml <H3>Detailed Server Patch Status</H3> "@ -Head $Style -preContent "Total Servers: $TotalServers" # Save the final report $Email | Out-File ".\SCCM_Patch_Report.html"
Key Changes Explained
- State Count Calculation: Uses
Group-Objectto tally up each state, and normalizes the long WMI error message to a cleaner "WMI Error" for the summary. - Stats HTML Fragment: The
-Fragmentswitch onConvertTo-HTMLgenerates just the table code (no full HTML wrapper), making it easy to insert into your main report's body. - Integrated Layout: The
-Bodyparameter now includes the summary header, stats table, and detailed status header, so the count section appears right at the top of your report. - Styling Fix: Corrected the typo
backgroud-colortobackground-colorin your CSS to ensure header styling works as expected.
内容的提问来源于stack exchange,提问作者Puneet Tiwari
相关产品推荐
相关产品推荐

