我需要向客户提供每月报告,列出我们环境中每个 Windows 服务器所需的更新理想情况下,报告应列出本月的更新以及我环境中需要这些更新的服务器。
我的 PowerShell 知识有限,但我找到了一些脚本(见下文)并对其进行了一些调整以获取更新和目标,但我不知道该怎么做结合这些信息编写一个脚本来展示每个服务器都需要特定的更新:
$wsus = Get-WsusServer -Name "<server-name>" -PortNumber 8530
$wsus.GetComputerTargets()
$updates = $wsus.GetUpdates() | where {$_.CreationDate -gt (Get-Date).addMonths(-1) }
# Iterate through every update, output some info
$results = ForEach ($update in $updates) {
$update.Title
$update.Description
$update.CreationDate
}
$results | Out-File C:\Temp\results.txt
## Select all WSUS clients export to file
$serverlist = ForEach ($server in $wsus.GetComputerTargets()) {
$server.FullDomainName
$server.OSDescription
}
$serverlist | Out-File C:\Temp\servers.txt
任何建议或意见都将非常感谢,谢谢!
答案1
我花了一些时间查看,选项太糟糕了,MS 肯定需要解决这个问题。
我使用了下面的内容,内容比较长,复制所有内容(包括块)到“endregion 发送电子邮件”中以供使用:
归功于https://github.com/proxb/WSUSReport/blob/master/WSUSReport.ps1对于主要脚本,我面临的挑战是让服务器更新所需的计数。
我在“#Failed Installations”部分中的第 275 行或 Sort Computername 之后添加了:
#Needed Count
$computerscope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$GroupNeededHash=@{}
$ComputerUpdatesNeeded = $wsus.GetSummariesPerComputerTarget($updatescope,$computerscope) | Select @{L='ComputerTarget';E={($wsus.GetComputerTarget([guid]$_.ComputerTargetId)).FullDomainName}}, `
@{L='NeededCount';E={($_.DownloadedCount + $_.NotInstalledCount)}} | Where-Object { $_.NeededCount -ne '0' }| Sort NeededCount -Descending | ForEach {
}
然后到第 538 行或“#endregion Failed Update Install”之后:
#region Needed Update Install
$Pre = @"
<div style='margin: 0px auto; BACKGROUND-COLOR:RED;Color:Black;font-weight:bold;FONT-SIZE: 14pt;'>
Needed Update Installations By Computer
</div>
"@
$Body = $wsus.GetSummariesPerComputerTarget($updatescope,$computerscope) | Select @{L='ComputerTarget';E={($wsus.GetComputerTarget([guid]$_.ComputerTargetId)).FullDomainName}}, `
@{L='NeededCount';E={($_.DownloadedCount + $_.NotInstalledCount)}} | Where-Object { $_.NeededCount -gt '4' }| Sort NeededCount -Descending | ConvertTo-Html -Fragment | Out-String | Set-AlternatingCSSClass -CSSEvenClass 'even' -CssOddClass 'odd'
$Post = "<br>"
$htmlFragment += $Pre,$Body,$Post
#endregion Needed Update Install