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 CatalogWindows The Microsoft Windows Update Catalog selected for Updates .PARAMETER WindowsBuild The Windows OS Build .PARAMETER WindowsProfile Microsoft Office Update Type .PARAMETER RepositoryRootPath Full Path of the OSDUpdate Repository .PARAMETER GridView Displays the results in GridView with -PassThru #> function Get-OSDUpdateDownloads { [CmdletBinding(DefaultParameterSetName = 'Office')] PARAM ( [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 = '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, [Parameter(Mandatory = $True)] [string]$RepositoryRootPath, [switch]$GridView ) #=================================================================================================== # Variables #=================================================================================================== $OSDUpdateDownloads = @() #=================================================================================================== # Repository #=================================================================================================== if ($CatalogOffice) { New-OSDUpdateRepository -RepositoryRootPath "$RepositoryRootPath" -Catalog $CatalogOffice $DownloadsPath = "$RepositoryRootPath\$CatalogOffice" } if ($CatalogWindows) { New-OSDUpdateRepository -RepositoryRootPath "$RepositoryRootPath" -Catalog $CatalogWindows $DownloadsPath = "$RepositoryRootPath\$CatalogWindows" } #=================================================================================================== # Catalogs #=================================================================================================== if ($CatalogOffice) { if ($OfficeProfile) { $OSDUpdateDownloads = Get-OSDUpdate -CatalogOffice $CatalogOffice -OfficeProfile $OfficeProfile } else { $OSDUpdateDownloads = Get-OSDUpdate -CatalogOffice $CatalogOffice } } if ($CatalogWindows) { $OSDUpdateDownloads = Get-OSDUpdate -CatalogWindows $CatalogWindows } #=================================================================================================== # Windows Build #=================================================================================================== if ($WindowsBuild -eq 1809) {$OSDUpdateDownloads = $OSDUpdateDownloads | Where-Object {$_.LegacyName -like "*RS5*" -or $_.Title -like "*1809*"}} if ($WindowsBuild -eq 1803) {$OSDUpdateDownloads = $OSDUpdateDownloads | Where-Object {$_.LegacyName -like "*RS4*" -or $_.Title -like "*1803*"}} if ($WindowsBuild -eq 1709) {$OSDUpdateDownloads = $OSDUpdateDownloads | Where-Object {$_.LegacyName -like "*RS3*" -or $_.Title -like "*1709*"}} if ($WindowsBuild -eq 1703) {$OSDUpdateDownloads = $OSDUpdateDownloads | Where-Object {$_.LegacyName -like "*RS2*" -or $_.Title -like "*1703*"}} if ($WindowsBuild -eq 1607) {$OSDUpdateDownloads = $OSDUpdateDownloads | Where-Object {$_.LegacyName -like "*RS1*" -or $_.Title -like "*1607*"}} if ($WindowsBuild -eq 1511) {$OSDUpdateDownloads = $OSDUpdateDownloads | Where-Object {$_.LegacyName -like "*TH2*" -or $_.Title -like "*1511*"}} if ($WindowsBuild -eq 1507) {$OSDUpdateDownloads = $OSDUpdateDownloads | Where-Object {$_.LegacyName -like "*TH1*" -or $_.Title -like "*1507*"}} #=================================================================================================== # Windows Profile #=================================================================================================== if ($WindowsProfile -eq 'SSU Servicing Stack Update') {$OSDUpdateDownloads = $OSDUpdateDownloads | Where-Object {$_.LegacyName -like "*ServicingStackUpdate*"}} if ($WindowsProfile -eq 'LCU Latest Cumulative Update') {$OSDUpdateDownloads = $OSDUpdateDownloads | Where-Object {$_.Title -like "*Cumulative Update for Windows*"}} if ($WindowsProfile -eq 'DNCU DotNet Cumulative Update') {$OSDUpdateDownloads = $OSDUpdateDownloads | Where-Object {$_.LegacyName -like "*DotNet*"}} if ($WindowsProfile -eq 'AFPU Adobe Flash Player') {$OSDUpdateDownloads = $OSDUpdateDownloads | Where-Object {$_.Title -like "*Adobe*"}} if ($WindowsProfile -eq 'DUSU Dynamic Update Setup Update') {$OSDUpdateDownloads = $OSDUpdateDownloads | Where-Object {$_.LegacyName -like "*SetupDU*"}} if ($WindowsProfile -eq 'DUCU Dynamic Update Component Update') {$OSDUpdateDownloads = $OSDUpdateDownloads | Where-Object {$_.LegacyName -like "*CriticalDU*" -or $_.LegacyName -like "*SafeOSDU*"}} #=================================================================================================== # GridView #=================================================================================================== if ($GridView.IsPresent) {$OSDUpdateDownloads = $OSDUpdateDownloads | Out-GridView -PassThru -Title "Select OSDUpdate Downloads"} #=================================================================================================== # Download #=================================================================================================== $OSDUpdateDownloads = $OSDUpdateDownloads | Sort-Object DateCreated if ($CatalogOffice) { foreach ($Update in $OSDUpdateDownloads) { $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 "$($Update.Title)" -ForegroundColor Cyan Write-Host "$DownloadDirectory\$MspFile" -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" } if ((Test-Path "$DownloadDirectory\$UpdateFile") -and (!(Test-Path "$DownloadDirectory\$MspFile"))) { Write-Host "Expanding $MspFile from $DownloadDirectory\$UpdateFile" -ForegroundColor DarkGray expand "$DownloadDirectory\$UpdateFile" -F:* "$DownloadDirectory" | Out-Null } if ((Test-Path "$DownloadDirectory\$UpdateFile") -and (Test-Path "$DownloadDirectory\$MspFile")) { Write-Host "Removing $DownloadDirectory\$UpdateFile" -ForegroundColor DarkGray 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 DarkGray Write-Host "Source: $DownloadDirectory\$MspFile" -ForegroundColor DarkGray Write-Host "Destination: $OfficeSetupUpdatesPath\$MspFile" -ForegroundColor DarkGray Copy-Item -Path "$DownloadDirectory\$MspFile" "$OfficeSetupUpdatesPath\$MspFile" -Force Write-Host "" } } } if ($CatalogWindows) { foreach ($Update in $OSDUpdateDownloads) { $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" } } } } |