Public/Get-OSDUpdate.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<#
.SYNOPSIS
Gets Current Microsoft Updates
 
.DESCRIPTION
Gets Current Microsoft Updates
 
.LINK
https://www.osdeploy.com/osdupdate/docs/functions/get-osdupdate
 
.PARAMETER CatalogOffice
The Microsoft Office Update Catalog selected for Updates
 
.PARAMETER OfficeProfile
Microsoft Office Update Type
 
.PARAMETER CatalogWindows
The Microsoft Windows Update Catalog selected for Updates
 
.PARAMETER WindowsBuild
The Windows OS Build
 
.PARAMETER WindowsProfile
Microsoft Office Update Type
 
.PARAMETER GridView
Displays the results in GridView with -PassThru
#>

function Get-OSDUpdate {
    [CmdletBinding(DefaultParameterSetName = 'Office')]
    PARAM (
        [Parameter(
        ParameterSetName = 'Office',
        Mandatory = $True,
        Position = 0)]
        [ValidateSet(
            'Office 2010 32-Bit',
            'Office 2010 64-Bit',
            'Office 2013 32-Bit',
            'Office 2013 64-Bit',
            'Office 2016 32-Bit',
            'Office 2016 64-Bit')]
        [string]$CatalogOffice,

        [Parameter(
            ParameterSetName = 'Office',
            Mandatory = $True)]
        [ValidateSet(
            'Default',
            'Proofing',
            'Language',
            'All')]
        [string]$OfficeProfile,

        [Parameter(
        ParameterSetName = 'Windows',
        Mandatory = $True,
        Position = 0)]
        [ValidateSet(
            'Windows 7 x86',
            'Windows 7 x64',
            'Windows 10 x86',
            'Windows 10 x64',
            'Windows Server 2012 R2 x64',
            'Windows Server 2016 x64',
            'Windows Server 2019 x64')]
        [string]$CatalogWindows,

        [Parameter (ParameterSetName = 'Windows')]
        [ValidateSet (1809,1803,1709,1703,1607,1511,1507)]
        [string]$WindowsBuild,

        [Parameter (ParameterSetName = 'Windows')]
        [ValidateSet ('SSU Servicing Stack Update','LCU Latest Cumulative Update','DNCU DotNet Cumulative Update','AFPU Adobe Flash Player','DUSU Dynamic Update Setup Update','DUCU Dynamic Update Component Update')]
        [string]$WindowsProfile,

        [switch]$GridView
    )
    Write-Warning "Updates are Current as of February 20, 2019"
    #===================================================================================================
    # Variables
    #===================================================================================================
    $AllOSDUpdates = @()
    #===================================================================================================
    # Update Catalogs
    #===================================================================================================
    if ($CatalogOffice) {$UpdateCatalogs = Get-ChildItem -Path "$($MyInvocation.MyCommand.Module.ModuleBase)\Catalogs\*" -Include "*$($CatalogOffice).xml"}
    if ($CatalogWindows) {$UpdateCatalogs = Get-ChildItem -Path "$($MyInvocation.MyCommand.Module.ModuleBase)\Catalogs\*" -Include "*$($CatalogWindows).xml"}
    #===================================================================================================
    # Import
    #===================================================================================================
    foreach ($UpdateCatalog in $UpdateCatalogs) {$AllOSDUpdates += Import-Clixml -Path "$($UpdateCatalog.FullName)"}
    #===================================================================================================
    # Standard Filters
    #===================================================================================================
    $AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.FileName -notlike "*.exe"}
    $AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.FileName -notlike "*.psf"}
    $AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.FileName -notlike "*.txt"}
    $AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.FileName -notlike "*delta.exe"}
    $AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.FileName -notlike "*express.cab"}
    #===================================================================================================
    # Office Superseded
    #===================================================================================================
    if ($CatalogOffice) {
        $AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.FileName -notlike "*Sharepoint*"}
        $AllOSDUpdates = $AllOSDUpdates | Sort-Object OriginUri -Unique
        $AllOSDUpdates = $AllOSDUpdates | Sort-Object DateCreated -Descending

        $CurrentUpdates = @()
        $SupersededUpdates = @()

        foreach ($OfficeUpdate in $AllOSDUpdates) {
            $SkipUpdate = $false

            foreach ($CurrentUpdate in $CurrentUpdates) {
                if ($($OfficeUpdate.FileName) -eq $($CurrentUpdate.FileName)) {$SkipUpdate = $true}
            }

            if ($SkipUpdate) {
                Write-Host "Superseded: $($OfficeUpdate.DateCreated) $($OfficeUpdate.Title) $($OfficeUpdate.FileName)" -ForegroundColor DarkGray
                $SupersededUpdates += $OfficeUpdate
            } else {
                $CurrentUpdates += $OfficeUpdate
            }
        }
        $AllOSDUpdates = $CurrentUpdates
    }
    #===================================================================================================
    # Office Profile
    #===================================================================================================
    if ($OfficeProfile -eq 'Default') {
        $AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.FileName -like "*none*" -or $_.FileName -like "*en-us*"}
        $AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.Title -notlike "*Language Pack*"}
    }

    if ($OfficeProfile -eq 'Language') {
        $AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.FileName -notlike "*none*" -and $_.FileName -notlike "*en-us*"}
    }

    if ($OfficeProfile -eq 'Proofing') {
        $AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.FileName -like "*Proof*"}
    }
    #===================================================================================================
    # Windows Build
    #===================================================================================================
    if ($WindowsBuild -eq 1809) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*RS5*" -or $_.Title -like "*1809*"}}
    if ($WindowsBuild -eq 1803) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*RS4*" -or $_.Title -like "*1803*"}}
    if ($WindowsBuild -eq 1709) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*RS3*" -or $_.Title -like "*1709*"}}
    if ($WindowsBuild -eq 1703) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*RS2*" -or $_.Title -like "*1703*"}}
    if ($WindowsBuild -eq 1607) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*RS1*" -or $_.Title -like "*1607*"}}
    if ($WindowsBuild -eq 1511) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*TH2*" -or $_.Title -like "*1511*"}}
    if ($WindowsBuild -eq 1507) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*TH1*" -or $_.Title -like "*1507*"}}
    #===================================================================================================
    # Windows Profile
    #===================================================================================================
    if ($WindowsProfile -eq 'SSU Servicing Stack Update') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*ServicingStackUpdate*"}}
    if ($WindowsProfile -eq 'LCU Latest Cumulative Update') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.Title -like "*Cumulative Update for Windows*"}}
    if ($WindowsProfile -eq 'DNCU DotNet Cumulative Update') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*DotNet*"}}
    if ($WindowsProfile -eq 'AFPU Adobe Flash Player') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.Title -like "*Adobe*"}}
    if ($WindowsProfile -eq 'DUSU Dynamic Update Setup Update') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*SetupDU*"}}
    if ($WindowsProfile -eq 'DUCU Dynamic Update Component Update') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*CriticalDU*" -or $_.LegacyName -like "*SafeOSDU*"}}
    #===================================================================================================
    # Arch
    #===================================================================================================
<# if ($Office -like "*64*" -or $Windows -like "*x64*") {
        $AllOSDUpdates = $AllOSDUpdates | `
        Where-Object {
            ($_.Title -like "*x64*") `
        -or ($_.Title -like "*64-Bit*") `
        -or ($_.FileName -like "*x64*") `
        -or ($_.LegacyName -like "*x64*")
        }
    }
    if ($Office -like "*32*" -or $Windows -like "*x86*") {
        $AllOSDUpdates = $AllOSDUpdates | `
        Where-Object {
            ($_.Title -like "*x86*") `
        -or ($_.Title -like "*32-Bit*") `
        -or ($_.FileName -like "*x86*") `
        -or ($_.LegacyName -like "*x86*")
        }
    } #>

    #===================================================================================================
    # GridView
    #===================================================================================================
    $AllOSDUpdates = $AllOSDUpdates | Sort-Object -Property @{Expression = {$_.DateCreated}; Ascending = $false}, Size -Descending
    #===================================================================================================
    # GridView
    #===================================================================================================
    if ($GridView.IsPresent) {$AllOSDUpdates = $AllOSDUpdates | Out-GridView -PassThru -Title 'Select OSDUpdates'}
    #===================================================================================================
    # Return
    #===================================================================================================
    Return $AllOSDUpdates
}

Sort-Object -Property @{Expression = {$_.DateCreated}; Ascending = $false}, Size -Descending