Public/Get-OSDUpdate.txt

<#
.SYNOPSIS
Returns an Array of Microsoft Updates
 
.DESCRIPTION
Returns an Array of Microsoft Updates contained in the local WSUS Catalogs
 
.LINK
https://osdupdate.osdeploy.com/module/functions/get-osdupdate
 
.PARAMETER GridView
Displays the results in GridView with -PassThru
 
.PARAMETER Silent
Hide the Current Update Date information
#>
 
function Get-OSDUpdate {
    [CmdletBinding()]
    PARAM (
        [switch]$GridView,
        [switch]$Silent
    )
    #===================================================================================================
    # Update Information
    #===================================================================================================
    $OSDSUSCatalogs = "$((Get-Module -ListAvailable -Name OSDSUS).ModuleBase)\Catalogs"
    #Write-Verbose "$OSDSUSCatalogs" -Verbose
 
    $OSDSUSVersion = $((Get-Module -ListAvailable -Name OSDSUS | Sort-Object Version | Select-Object Version -Last 1).Version)
    #Write-Verbose "$OSDSUSVersion" -Verbose
 
    if (!($Silent.IsPresent)) {
        Write-Verbose "OSDSUS $OSDSUSVersion" -Verbose
        Write-Verbose "http://osdsus.osdeploy.com/release" -Verbose
        Write-Verbose 'Gathering Updates ...' -Verbose
    }
    #===================================================================================================
    # Variables
    #===================================================================================================
    $OSDUpdate = @()
    #===================================================================================================
    # UpdateCatalogs
    #===================================================================================================
    $OSDUpdateCatalogs = Get-ChildItem -Path "$OSDSUSCatalogs\*" -Include "*.xml" -Recurse
    #===================================================================================================
    # Import Catalog XML Files
    #===================================================================================================
    foreach ($OSDUpdateCatalog in $OSDUpdateCatalogs) {
<# #Write-Verbose "Importing $($OSDUpdateCatalog.Name)" -Verbose
        if ($OSDUpdateCatalog.Name -match 'Office') {
 
            $OfficeUpdates = @()
            $OfficeUpdates = Import-Clixml -Path "$($OSDUpdateCatalog.FullName)"
 
            $OfficeUpdates = $OfficeUpdates | Sort-Object OriginUri -Unique
            $OfficeUpdates = $OfficeUpdates | Sort-Object CreationDate -Descending
 
            #$OfficeUpdates | Out-GridView
 
            $CurrentUpdates = @()
            $SupersededUpdates = @()
 
            foreach ($OfficeUpdate in $OfficeUpdates) {
                $SkipUpdate = $false
     
                foreach ($CurrentUpdate in $CurrentUpdates) {
                    if ($($OfficeUpdate.FileName) -eq $($CurrentUpdate.FileName)) {$SkipUpdate = $true}
                }
     
                if ($SkipUpdate) {
                    $SupersededUpdates += $OfficeUpdate
                } else {
                    $CurrentUpdates += $OfficeUpdate
                }
            }
            $OSDUpdate += $CurrentUpdates
        } else {
            $OSDUpdate += Import-Clixml -Path "$($OSDUpdateCatalog.FullName)"
        } #>
        $OSDUpdate += Import-Clixml -Path "$($OSDUpdateCatalog.FullName)"
    }
    #===================================================================================================
    # Standard Filters
    #===================================================================================================
    $OSDUpdate = $OSDUpdate | Where-Object {$_.FileName -notlike "*.exe"}
    $OSDUpdate = $OSDUpdate | Where-Object {$_.FileName -notlike "*.psf"}
    $OSDUpdate = $OSDUpdate | Where-Object {$_.FileName -notlike "*.txt"}
    $OSDUpdate = $OSDUpdate | Where-Object {$_.FileName -notlike "*delta.exe"}
    $OSDUpdate = $OSDUpdate | Where-Object {$_.FileName -notlike "*express.cab"}
    #===================================================================================================
    # Sorting
    #===================================================================================================
    #$OSDUpdate = $OSDUpdate | Sort-Object -Property @{Expression = {$_.CreationDate}; Ascending = $false}, Size -Descending
    $OSDUpdate = $OSDUpdate | Sort-Object -Property CreationDate -Descending
    #===================================================================================================
    # GridView
    #===================================================================================================
    if ($GridView.IsPresent) {
        $OSDUpdate = $OSDUpdate | Out-GridView -PassThru -Title 'Select OSDUpdates to Return'
    }
    #===================================================================================================
    # Return
    #===================================================================================================
    Return $OSDUpdate
}