Private/Get-UpdateMonthly.ps1
Function Get-UpdateMonthly { <# .SYNOPSIS Builds an object with the Windows 8.1/7 Monthly Update. #> [OutputType([System.Management.Automation.PSObject])] [CmdletBinding(SupportsShouldProcess = $False)] Param ( [Parameter(Mandatory = $False, Position = 0, ValueFromPipeline)] [ValidateNotNullOrEmpty()] [System.Xml.XmlNode] $UpdateFeed ) # Get module strings from the JSON $resourceStrings = Get-ModuleResource # Filter object matching desired update type $updateList = New-Object -TypeName System.Collections.ArrayList ForEach ($item in $UpdateFeed.feed.entry) { If ($item.title -match $resourceStrings.SearchStrings.MonthlyRollup) { Write-Verbose -Message "$($MyInvocation.MyCommand): matched item [$($item.title)]" $PSObject = [PSCustomObject] @{ Title = $item.title ID = $item.id Updated = $item.updated } $updateList.Add($PSObject) | Out-Null } } # Filter and select the most current update If ($updateList.Count -ge 1) { $sortedUpdateList = New-Object -TypeName System.Collections.ArrayList ForEach ($update in $updateList) { $PSObject = [PSCustomObject] @{ Title = $update.title ID = "KB{0}" -f ($update.id).Split(":")[2] Updated = ([DateTime]::Parse($update.updated)) } $sortedUpdateList.Add($PSObject) | Out-Null } $latestUpdate = $sortedUpdateList | Sort-Object -Property Updated -Descending | Select-Object -First 1 Write-Verbose -Message "$($MyInvocation.MyCommand): selected item [$($latestUpdate.title)]" } # Return object to the pipeline Write-Output -InputObject $latestUpdate } |