Public/Get-OSDBuilderDownloads.ps1
function Get-OSDBuilderDownloads { [CmdletBinding(DefaultParameterSetName='Updates')] PARAM ( [switch]$Download, [switch]$GridView, #=================================================================================================== # Updates #=================================================================================================== [Parameter(ParameterSetName = 'Updates', Mandatory = $True)] [ValidateSet( 'Windows 10 x64', 'Windows 10 x86', 'Windows Server 2012 R2 x64', 'Windows Server 2016 x64', 'Windows Server 2019 x64')] [string]$UpdateCatalog, [Parameter(ParameterSetName = 'Updates')] [string]$KBTitle, [Parameter(ParameterSetName = 'Updates')] [switch]$RemoveSuperseded, [Parameter(ParameterSetName = 'Updates')] [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]$UpdateProfile, [Parameter(ParameterSetName = 'Updates')] [ValidateSet('1903','1809','1803','1709','1703','1607','1511','1507')] [string]$WindowsBuild, #=================================================================================================== # Language #=================================================================================================== [Parameter(ParameterSetName = 'Language', Mandatory = $True)] [ValidateSet( 'Windows 10 x64 Language Pack', 'Windows 10 x64 Language Interface Pack', 'Windows 10 x86 Language Pack', 'Windows 10 x86 Language Interface Pack')] [string]$LanguageCatalog, [Parameter(ParameterSetName = 'Language')] [ValidateSet( 'ar-SA','bg-BG','zh-CN','zh-TW','hr-HR','cs-CZ', 'da-DK','nl-NL','en-US','en-GB','et-EE','fi-FI', 'fr-CA','fr-FR','de-DE','el-GR','he-IL','hu-HU', 'it-IT','ja-JP','ko-KR','lv-LV','lt-LT','nb-NO', 'pl-PL','pt-BR','pt-PT','ro-RO','ru-RU','sr-Latn-RS', 'sk-SK','sl-SI','es-MX','es-ES','sv-SE','th-TH','tr-TR','uk-UA')] [string]$LanguagePack, [Parameter(ParameterSetName = 'Language')] [ValidateSet( 'af-ZA','am-ET','as-IN','az-Latn-AZ','be-BY', 'bn-BD','bn-IN','bs-Latn-BA','ca-ES','ca-ES-valencia', 'chr-CHER-US','cy-GB','eu-ES','fa-IR','fil-PH', 'ga-IE','gd-GB','gl-ES','gu-IN','ha-Latn-NG','hi-IN', 'hy-AM','id-ID','ig-NG','is-IS','ka-GE','kk-KZ','km-KH', 'kn-IN','kok-IN','ku-ARAB-IQ','ky-KG','lb-LU','lo-LA', 'mi-NZ','mk-MK','ml-IN','mn-MN','mr-IN','ms-MY','mt-MT', 'ne-NP','nn-NO','nso-ZA','or-IN','pa-Arab-PK','pa-IN','prs-AF', 'quc-Latn-GT','quz-PE','rw-RW','sd-Arab-PK','si-LK','sq-AL', 'sr-Cyrl-BA','sr-Cyrl-RS','sw-KE','ta-IN','te-IN','tg-Cyrl-TJ', 'ti-ET','tk-TM','tn-ZA','tt-RU','ug-CN','ur-PK','uz-Latn-UZ', 'vi-VN','wo-SN','xh-ZA','yo-NG','zu-ZA')] [string]$LanguageInterfacePack ) BEGIN { #Write-Host '========================================================================================' -ForegroundColor DarkGray #Write-Host "$($MyInvocation.MyCommand.Name) BEGIN" -ForegroundColor Green <# Write-Warning 'This function is for testing only' Write-Warning "Updates are downloaded to $OSBuilderPath\Updates" Write-Warning 'These updates are not used by OSDBuilder . . . yet' Write-Warning 'Not all Catalogs are in place' #> Get-OSBuilder -CreatePaths -HideDetails } PROCESS { #Write-Host '========================================================================================' -ForegroundColor DarkGray #Write-Host "$($MyInvocation.MyCommand.Name) PROCESS" -ForegroundColor Green #=================================================================================================== # Get Catalogs #=================================================================================================== if ($PSCmdlet.ParameterSetName -eq 'Updates') { $Catalog = $UpdateCatalog } if ($PSCmdlet.ParameterSetName -eq 'Language') { $Catalog = $LanguageCatalog } $OSDCatalogs = Get-ChildItem -Path "$($MyInvocation.MyCommand.Module.ModuleBase)\Catalogs\*" -Include "$($Catalog).xml" #=================================================================================================== # Import Catalogs #=================================================================================================== $AllOSDUpdates = @() foreach ($OSDCatalog in $OSDCatalogs) {$AllOSDUpdates += Import-Clixml -Path "$($OSDCatalog.FullName)"} #=================================================================================================== # Replace #=================================================================================================== foreach ($Update in $AllOSDUpdates) { $Update.Title = $Update.Title -replace ',','' $Update.Title = $Update.Title -replace '"','' } #=================================================================================================== # Existing Updates #=================================================================================================== if ($PSCmdlet.ParameterSetName -eq 'Updates') { $DownloadedUpdates = @() $ExistingUpdates = @() $SupersededUpdates = @() $ExistingUpdates = Get-ChildItem -Path "$OSBuilderPath\Updates\$Catalog\*" -Directory foreach ($Update in $ExistingUpdates) { if ($AllOSDUpdates.Title -NotContains $Update.Name) {$SupersededUpdates += $Update.FullName} else {$DownloadedUpdates += $Update.Name} } } #=================================================================================================== # Superseded Updates #=================================================================================================== if ($PSCmdlet.ParameterSetName -eq '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" } } } #=================================================================================================== # Get Downloaded Updates #=================================================================================================== foreach ($Update in $AllOSDUpdates) { $FullUpdatePath = "$OSBuilderPath\Updates\$Catalog\$($Update.Title)\$($Update.FileName)" if (Test-Path $FullUpdatePath) { $Update.State = "Downloaded" } } #=================================================================================================== # 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"} $AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.Title -notlike "* Next *"} #=================================================================================================== # 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 ($UpdateProfile -eq 'SSU Servicing Stack Update') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*ServicingStackUpdate*"}} if ($UpdateProfile -eq 'LCU Latest Cumulative Update') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.Title -like "*Cumulative Update for Windows*"}} if ($UpdateProfile -eq 'DNCU DotNet Cumulative Update') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*DotNet*"}} if ($UpdateProfile -eq 'AFPU Adobe Flash Player') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.Title -like "*Adobe*"}} if ($UpdateProfile -eq 'DUSU Dynamic Update Setup Update') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*SetupDU*"}} if ($UpdateProfile -eq 'DUCU Dynamic Update Component Update') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.LegacyName -like "*CriticalDU*" -or $_.LegacyName -like "*SafeOSDU*"}} #=================================================================================================== # KB Title #=================================================================================================== if ($KBTitle) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.Title -like "*$KBTitle*"}} #=================================================================================================== # Get Available Updates #=================================================================================================== $AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.State -ne 'Downloaded'} #=================================================================================================== # Select Updates with GridView #=================================================================================================== if ($GridView.IsPresent) {$AllOSDUpdates = $AllOSDUpdates | Out-GridView -PassThru -Title 'Select Updates to Download and press OK'} #=================================================================================================== # Download Updates #=================================================================================================== if ($Download.IsPresent) { foreach ($Update in $AllOSDUpdates) { $DownloadPath = "$OSBuilderPath\Updates\$Catalog\$($Update.Title)" $DownloadFullPath = "$DownloadPath\$($Update.FileName)" if (!(Test-Path $DownloadPath)) {New-Item -Path "$DownloadPath" -ItemType Directory -Force | Out-Null} if (!(Test-Path $DownloadFullPath)) { Write-Host "$DownloadFullPath" -ForegroundColor Cyan Write-Host "$($Update.OriginUri)" -ForegroundColor DarkGray #$WebClient = New-Object System.Net.WebClient #$WebClient.DownloadFile("$($Update.OriginUri)","$DownloadFullPath") Start-BitsTransfer -Source $Update.OriginUri -Destination $DownloadFullPath } else { #Write-Warning "Exists: $($Update.Title)" } } } else { Return $AllOSDUpdates } } END { #Write-Host '========================================================================================' -ForegroundColor DarkGray #Write-Host "$($MyInvocation.MyCommand.Name) END" -ForegroundColor Green } } |