WSUS 更新报告

WSUS 更新服务 · 第 6 篇 · 适用于 Windows Server 2019 / 2022 / 2025

📑 目录

  1. 概述
  2. 内置报告
  3. 自定义报告
  4. 监控与告警
  5. 常见问题

1. 概述

WSUS 提供丰富的内置报告功能,帮助管理员了解更新部署状态、计算机合规性、同步状态等关键信息。结合 PowerShell 和第三方工具,还可以实现自定义报告和自动化监控。

2. 内置报告

WSUS 管理控制台提供以下内置报告类型:

1

打开 WSUS 管理控制台,展开服务器节点

2

点击"报告",选择需要的报告类型

3

配置筛选条件(更新分类、计算机组、时间范围等)

4

点击"生成报告",查看或导出为 PDF/Excel

PowerShell
# 获取 WSUS 服务器
$wsus = Get-WsusServer

# 获取计算机摘要报告
$computers = $wsus.GetComputerTargetSummaries()
$computers | Select-Object ComputerTargetId, FullDomainName, 
    @{N="NeededCount";E={$_.NeededCount}},
    @{N="InstalledCount";E={$_.InstalledCount}},
    @{N="LastReported";E={$_.LastReportedStatusTime}} |
    Format-Table -AutoSize

# 获取更新状态统计
$updates = $wsus.GetUpdates()
$updates | Group-Object IsApproved | Select-Object Name, Count

3. 自定义报告

使用 PowerShell 生成自定义合规性报告:

PowerShell
# 自定义合规性报告
$wsus = Get-WsusServer
$computerGroup = $wsus.GetComputerTargetGroups() | Where-Object { $_.Name -eq "生产服务器组" }
$computers = $computerGroup.GetComputerTargets()

$report = foreach ($computer in $computers) {
    $status = $computer.GetUpdateInstallationSummary()
    [PSCustomObject]@{
        ComputerName = $computer.FullDomainName
        Needed = $status.NotInstalledCount
        Downloaded = $status.DownloadedCount
        Installed = $status.InstalledCount
        Failed = $status.FailedCount
        LastSync = $computer.LastReportedStatusTime
    }
}

$report | Export-Csv -Path "C:\Reports\WSUS-Compliance.csv" -NoTypeInformation
Write-Host "合规性报告已导出到 C:\Reports\WSUS-Compliance.csv"

4. 监控与告警

设置自动化监控,及时发现更新部署问题:

PowerShell
# WSUS 监控脚本(可设置为计划任务)
$wsus = Get-WsusServer

# 检查长时间未同步的计算机(超过 7 天)
$threshold = (Get-Date).AddDays(-7)
$staleComputers = $wsus.GetComputerTargets() | Where-Object { 
    $_.LastReportedStatusTime -lt $threshold 
}

if ($staleComputers) {
    $subject = "WSUS 告警:$($staleComputers.Count) 台计算机未报告"
    $body = $staleComputers | Select-Object FullDomainName, LastReportedStatusTime | Format-Table | Out-String
    
    Send-MailMessage -To "admin@iehang.cn" -From "wsus@iehang.cn" `
        -Subject $subject -Body $body -SmtpServer "mail.iehang.cn"
}

5. 常见问题

Q1:报告数据不准确?

确保所有客户端已报告状态(Last Reported Status Time 为近期),检查 WSUS 数据库连接正常,必要时运行 WSUS 服务器清理向导。

Q2:如何导出历史报告?

WSUS 内置报告支持导出为 PDF、Excel 或 CSV。对于历史数据,建议定期运行 PowerShell 脚本导出到共享文件夹存档。