Public/Get-OSDUpdate.ps1
<#
.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 } |