Public/Get-OSDUpdateDownloads.ps1
<# .SYNOPSIS Downloads Current Microsoft Updates .DESCRIPTION Downloads Current Microsoft Updates Requires BITS for downloading the updates Requires Internet access for downloading the updates .LINK https://www.osdeploy.com/osdupdate/docs/functions/get-osdupdatedownloads .PARAMETER CatalogOffice The Microsoft Office Update Catalog selected for Updates .PARAMETER OfficeProfile Microsoft Office Update Type .PARAMETER OfficeSetupUpdatesPath This is the Updates directory in your Office installation source MSP files will be extracted from the DownloadsPath This directory should be cleared first .PARAMETER RemoveSuperseded Removes the Superseded Microsoft Office Updates from the Repository .PARAMETER CatalogWindows The Microsoft Windows Update Catalog selected for Updates .PARAMETER UpdateArch Architecture of the Update .PARAMETER UpdateBuild Windows Build for the Update .PARAMETER UpdateGroup Windows Update Type .PARAMETER GridView Displays the results in GridView with -PassThru .PARAMETER RepositoryRootPath Full Path of the OSDUpdate Repository #> function Get-OSDUpdateDownloads { [CmdletBinding(DefaultParameterSetName = 'Office')] PARAM ( #=================================================================================================== # Both #=================================================================================================== [switch]$GridView, [Parameter(Mandatory = $True)] [string]$RepositoryRootPath, #=================================================================================================== # Office Tab Only #=================================================================================================== [Parameter(ParameterSetName = 'Office', Mandatory = $True)] [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 = 'Office')] [string]$OfficeSetupUpdatesPath, [Parameter(ParameterSetName = 'Office')] [switch]$RemoveSuperseded, #=================================================================================================== # Windows Tab Only #=================================================================================================== [Parameter(ParameterSetName = 'Windows', Mandatory = $True)] [ValidateSet( 'Windows 7', 'Windows 8.1', 'Windows 10', 'Windows 10 Dynamic Update', 'Windows 10 Feature On Demand', 'Windows 10 Language Packs', 'Windows 10 Language Interface Packs', 'Windows Server 2012 R2', 'Windows Server 2016', 'Windows Server 2019')] [string]$CatalogWindows, [Parameter (ParameterSetName = 'Windows')] [ValidateSet ('x64','x86')] [string]$UpdateArch, [Parameter (ParameterSetName = 'Windows')] [ValidateSet (1809,1803,1709,1703,1607,1511,1507)] [string]$UpdateBuild, [Parameter(ParameterSetName = 'Windows')] [ValidateSet( 'Adobe Flash Player', 'DotNet Framework', 'Dynamic Update Setup', 'Dynamic Update Component', 'Latest Cumulative Update LCU', 'Servicing Stack Update SSU')] [string]$UpdateGroup ) #=================================================================================================== # Variables #=================================================================================================== $AllOSDUpdates = @() #=================================================================================================== # Repository #=================================================================================================== if ($CatalogOffice) { New-OSDUpdateRepository -RepositoryRootPath "$RepositoryRootPath" -Catalog $CatalogOffice $DownloadsPath = "$RepositoryRootPath\$CatalogOffice" } if ($CatalogWindows) { New-OSDUpdateRepository -RepositoryRootPath "$RepositoryRootPath" -Catalog $CatalogWindows $DownloadsPath = "$RepositoryRootPath\$CatalogWindows" } #=================================================================================================== # CatalogOffice #=================================================================================================== if ($CatalogOffice) { $AllOSDUpdateDownloads = Get-OSDUpdate -CatalogOffice $CatalogOffice -OfficeProfile All -Silent if ($OfficeProfile) { $AllOSDUpdates = Get-OSDUpdate -CatalogOffice $CatalogOffice -OfficeProfile $OfficeProfile } else { $AllOSDUpdates = Get-OSDUpdate -CatalogOffice $CatalogOffice } #=================================================================================================== # Existing Updates #=================================================================================================== $ExistingUpdates = @() $SupersededUpdates = @() $ExistingUpdates = Get-ChildItem -Path "$DownloadsPath\*" -Directory -Recurse | Select-Object -Property * foreach ($Update in $ExistingUpdates) { if ($AllOSDUpdateDownloads.Title -NotContains $Update.Name) {$SupersededUpdates += $Update.FullName} } #=================================================================================================== # Superseded Updates #=================================================================================================== foreach ($Update in $SupersededUpdates) { if ($RemoveSuperseded.IsPresent) { Write-Warning "Removing Superseded: $Update" Remove-Item $Update -Recurse -Force | Out-Null } else { Write-Warning "Superseded: $Update" } } } #=================================================================================================== # Catalog Windows #=================================================================================================== if ($CatalogWindows) { $AllOSDUpdates = Get-OSDUpdate -CatalogWindows $CatalogWindows } #=================================================================================================== # UpdateArch #=================================================================================================== if ($UpdateArch -eq 'x64') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateArch -eq 'x64'}} if ($UpdateArch -eq 'x86') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateArch -eq 'x86'}} #=================================================================================================== # Update Build #=================================================================================================== if ($UpdateBuild -eq 1809) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateBuild -eq '1809'}} if ($UpdateBuild -eq 1803) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateBuild -eq '1803'}} if ($UpdateBuild -eq 1709) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateBuild -eq '1709'}} if ($UpdateBuild -eq 1703) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateBuild -eq '1703'}} if ($UpdateBuild -eq 1607) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateBuild -eq '1607'}} if ($UpdateBuild -eq 1511) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateBuild -eq '1511'}} if ($UpdateBuild -eq 1507) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateBuild -eq '1507'}} #=================================================================================================== # UpdateGroup #=================================================================================================== if ($UpdateGroup -eq 'Adobe Flash Player') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateGroup -eq 'AdobeSU'}} if ($UpdateGroup -eq 'DotNet Framework') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateGroup -like "DotNet*"}} if ($UpdateGroup -eq 'Dynamic Update Setup') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateGroup -eq 'SetupDU'}} if ($UpdateGroup -eq 'Dynamic Update Component') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateGroup -eq 'CriticalDU' -or $_.UpdateGroup -eq 'SafeOSDU'}} if ($UpdateGroup -eq 'Latest Cumulative Update LCU') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateGroup -eq 'LCU'}} if ($UpdateGroup -eq 'Servicing Stack Update SSU') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateGroup -eq 'SSU'}} #=================================================================================================== # GridView #=================================================================================================== if ($GridView.IsPresent) {$AllOSDUpdates = $AllOSDUpdates | Out-GridView -PassThru -Title "Select OSDUpdate Downloads"} #=================================================================================================== # Sort #=================================================================================================== $AllOSDUpdates = $AllOSDUpdates | Sort-Object DateCreated #=================================================================================================== # Download #=================================================================================================== if ($CatalogOffice) { foreach ($Update in $AllOSDUpdates) { $UpdateFile = $($Update.FileName) $MspFile = $UpdateFile -replace '.cab', '.msp' $DownloadDirectory = "$DownloadsPath\$($Update.Title)" if (!(Test-Path "$DownloadDirectory")) {New-Item -Path "$DownloadDirectory" -ItemType Directory -Force | Out-Null} if (Test-Path "$DownloadDirectory\$MspFile") { Write-Host "$DownloadDirectory\$MspFile" -ForegroundColor Cyan } else { Write-Host "$DownloadDirectory\$MspFile" -ForegroundColor Cyan Write-Host "Download: $($Update.OriginUri)" -ForegroundColor Gray Start-BitsTransfer -Source $($Update.OriginUri) -Destination "$DownloadDirectory\$UpdateFile" } if ((Test-Path "$DownloadDirectory\$UpdateFile") -and (!(Test-Path "$DownloadDirectory\$MspFile"))) { Write-Host "Expand: $DownloadDirectory\$MspFile" -ForegroundColor Gray expand "$DownloadDirectory\$UpdateFile" -F:* "$DownloadDirectory" | Out-Null } if ((Test-Path "$DownloadDirectory\$UpdateFile") -and (Test-Path "$DownloadDirectory\$MspFile")) { Write-Host "Remove: $DownloadDirectory\$UpdateFile" -ForegroundColor Gray Remove-Item "$DownloadDirectory\$UpdateFile" -Force | Out-Null } #=================================================================================================== # Office Setup Updates #=================================================================================================== if ($OfficeSetupUpdatesPath) { if (!(Test-Path "$OfficeSetupUpdatesPath")) {New-Item -Path "$OfficeSetupUpdatesPath" -ItemType Directory -Force | Out-Null} Write-Host "Date Created: $($Update.DateCreated)" -ForegroundColor Gray Write-Host "Source: $DownloadDirectory\$MspFile" -ForegroundColor Gray Write-Host "Destination: $OfficeSetupUpdatesPath\$MspFile" -ForegroundColor Gray Copy-Item -Path "$DownloadDirectory\$MspFile" "$OfficeSetupUpdatesPath\$MspFile" -Force Write-Host "" } } } if ($CatalogWindows) { foreach ($Update in $AllOSDUpdates) { $UpdateFile = $($Update.FileName) $DownloadDirectory = "$DownloadsPath\$($Update.Title)" if (!(Test-Path "$DownloadDirectory")) {New-Item -Path "$DownloadDirectory" -ItemType Directory -Force | Out-Null} if (Test-Path "$DownloadDirectory\$UpdateFile") { Write-Host "$($Update.Title)" -ForegroundColor Cyan Write-Host "$DownloadDirectory\$UpdateFile" -ForegroundColor DarkGray Write-Host "Update already downloaded" -ForegroundColor DarkGray } else { Write-Host "$($Update.Title)" -ForegroundColor Cyan Write-Host "$($Update.OriginUri)" -ForegroundColor DarkGray Write-Host "$DownloadDirectory\$UpdateFile" -ForegroundColor DarkGray Start-BitsTransfer -Source $($Update.OriginUri) -Destination "$DownloadDirectory\$UpdateFile" } } } } |