Score:0

PowerShell - List WSUS Updates Needed for Each Client

cn flag

I need to provide a monthly report to our client listing the updates needed by each Windows server in our environment. Ideally, the report would list the updates for the month and the servers in my environment that need them.

My PowerShell knowledge is limited but I found some scripts (see below) and tweaked them a bit to pull the updates and the targets, but I can't figure out a way to combine this information into one script that shows the specific updates are needed by each server:

$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

Any suggestions or advice would be greatly appreciated, thank you!

Score:0
tw flag

I spent some time looking, the options are awful, surely MS need to sort this out.

I have used the below which is lengthy, copy all to use including the blocks to the "endregion send email":

Credit to https://github.com/proxb/WSUSReport/blob/master/WSUSReport.ps1 for the main script, I had challenges to get the server updated needed count included.

I added to line 275 or after Sort Computername in "#Failed Installations" Section:


#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 {
}

and then to line 538 or after "#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

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.