Public/Update-OSDwindows.ps1
<# .SYNOPSIS Downloads Microsoft Windows Updates .DESCRIPTION Downloads Microsoft Windows Updates Requires BITS for downloading the updates Requires Internet access for downloading the updates .LINK https://www.osdeploy.com/osdupdate/docs/functions/update-osdwindows .PARAMETER OS Self Explanatory .PARAMETER OSVersion Windows OS Version. Does not apply to Windows Server 2012 R2 .PARAMETER OSArch Windows OS Architecture .PARAMETER Selection These are the types of Updates to filter .PARAMETER DownloadPath This is the path to download the updates #> function Update-OSDwindows { [CmdletBinding()] PARAM ( [Parameter(Mandatory)] [ValidateSet('Windows 10','Windows Server 2012 R2','Windows Server 2016','Windows Server 2019')] [string]$OS, [ValidateSet('1809','1803','1709','1703','1607','1511','1507')] [string]$OSVersion, [ValidateSet('x64','x86')] [string]$OSArch, [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]$Selection, [string]$DownloadPath ) Write-Warning "Updates are Current as of February 16, 2019" $AllWindowsUpdates = @() #=================================================================================================== # Catalogs #=================================================================================================== if ($OS -eq 'Windows 10') {$AllWindowsUpdates = Import-Clixml -Path "$($MyInvocation.MyCommand.Module.ModuleBase)\Catalogs\OSDBuild Windows 10.xml"} if ($OS -eq 'Windows Server 2012 R2') {$AllWindowsUpdates = Import-Clixml -Path "$($MyInvocation.MyCommand.Module.ModuleBase)\Catalogs\OSDBuild Windows Server 2012 R2.xml"} if ($OS -eq 'Windows Server 2016') {$AllWindowsUpdates = Import-Clixml -Path "$($MyInvocation.MyCommand.Module.ModuleBase)\Catalogs\OSDBuild Windows Server 2016.xml"} if ($OS -eq 'Windows Server 2019') {$AllWindowsUpdates = Import-Clixml -Path "$($MyInvocation.MyCommand.Module.ModuleBase)\Catalogs\OSDBuild Windows Server 2019.xml"} #=================================================================================================== # Standard Filters #=================================================================================================== $AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.FileName -notlike "*.psf"} $AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.FileName -notlike "*.txt"} $AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.FileName -notlike "*delta.exe*"} $AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.FileName -notlike "*express*"} $AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.LegacyName -notlike "*Next*"} $AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.Title -notlike "*Insider Preview*"} $AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.UpdateClassificationTitle -ne 'Drivers'} #=================================================================================================== # OSVersion #=================================================================================================== if (!($OS -eq 'Windows Server 2012 R2')) { if ($OSVersion -eq '1809') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.LegacyName -like "*RS5*" -or $_.Title -like "*1809*"}} if ($OSVersion -eq '1803') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.LegacyName -like "*RS4*" -or $_.Title -like "*1803*"}} if ($OSVersion -eq '1709') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.LegacyName -like "*RS3*" -or $_.Title -like "*1709*"}} if ($OSVersion -eq '1703') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.LegacyName -like "*RS2*" -or $_.Title -like "*1703*"}} if ($OSVersion -eq '1607') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.LegacyName -like "*RS1*" -or $_.Title -like "*1607*"}} if ($OSVersion -eq '1511') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.LegacyName -like "*TH2*" -or $_.Title -like "*1511*"}} if ($OSVersion -eq '1507') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.LegacyName -like "*TH1*" -or $_.Title -like "*1507*"}} } #=================================================================================================== # OSArch #=================================================================================================== if ($OSArch -eq 'x64') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.LegacyName -like "*x64*" -or $_.Title -like "*x64*" -or $_.Title -like "*64-Bit*"}} if ($OSArch -eq 'x86') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.LegacyName -like "*x86*" -or $_.Title -like "*x86*" -or $_.Title -like "*32-Bit*"}} #=================================================================================================== # Selection #=================================================================================================== if ($Selection -eq 'SSU Servicing Stack Update') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.LegacyName -like "*ServicingStackUpdate*"}} if ($Selection -eq 'LCU Latest Cumulative Update') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.Title -like "*Cumulative Update for Windows*"}} if ($Selection -eq 'DNCU DotNet Cumulative Update') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.LegacyName -like "*DotNet*"}} if ($Selection -eq 'AFPU Adobe Flash Player') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.Title -like "*Adobe*"}} if ($Selection -eq 'DUSU Dynamic Update Setup Update') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.LegacyName -like "*SetupDU*"}} if ($Selection -eq 'DUCU Dynamic Update Component Update') {$AllWindowsUpdates = $AllWindowsUpdates | Where-Object {$_.LegacyName -like "*CriticalDU*" -or $_.LegacyName -like "*SafeOSDU*"}} #=================================================================================================== # Sorting #=================================================================================================== $AllWindowsUpdates = $AllWindowsUpdates | Sort-Object OriginUri -Unique $AllWindowsUpdates = $AllWindowsUpdates | Sort-Object DateCreated -Descending #=================================================================================================== # Select Updates #=================================================================================================== $AllWindowsUpdates = $AllWindowsUpdates | Out-GridView -PassThru -Title "Select Windows Updates" #=================================================================================================== # Download #=================================================================================================== if ($DownloadPath) { Write-Host "DownloadPath: $DownloadPath" -ForegroundColor Cyan if (!(Test-Path "$DownloadPath")) {New-Item -Path "$DownloadPath" -ItemType Directory -Force | Out-Null} foreach ($Update in $AllWindowsUpdates) { $DownloadDirectory = "$DownloadPath\$($Update.Title)" $DownloadFile = $($Update.FileName) if (!(Test-Path "$DownloadDirectory")) {New-Item -Path "$DownloadDirectory" -ItemType Directory -Force | Out-Null} if (Test-Path "$DownloadDirectory\$DownloadFile") { Write-Warning "Update Exists: $DownloadDirectory\$DownloadFile" } else { Write-Host "$($Update.Title)" -ForegroundColor Cyan Write-Host "$($Update.OriginUri)" -ForegroundColor DarkGray Write-Host "$DownloadDirectory\$DownloadFile" -ForegroundColor DarkGray Start-BitsTransfer -Source $($Update.OriginUri) -Destination "$DownloadDirectory\$DownloadFile" } } } Return $AllWindowsUpdates } |