Public/Get-DownOSDUpdate.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
<#
.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-downosdupdate .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-DownOSDUpdate { [CmdletBinding(DefaultParameterSetName = 'Office')] PARAM ( #=================================================================================================== # Windows and Office #=================================================================================================== #[Parameter(ParameterSetName = 'Windows')] #[Parameter(ParameterSetName = 'Office')] [switch]$AddInstallScript, [Parameter(ParameterSetName = 'Windows')] [Parameter(ParameterSetName = 'Office')] [switch]$GridView, [switch]$RemoveSuperseded, [Parameter(Mandatory = $True)] [string]$RepositoryRootPath, #=================================================================================================== # Windows Tab Only #=================================================================================================== [Parameter(ParameterSetName = 'Windows', Mandatory = $True)] [ValidateSet( 'Windows 7', #'Windows 8.1', #'Windows 8.1 Dynamic Update', '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 2012 R2 Dynamic Update', 'Windows Server 2016', 'Windows Server 2019')] [string]$CatalogWindows, [Parameter (ParameterSetName = 'Windows')] [ValidateSet ('x64','x86')] [string]$UpdateArch, [Parameter (ParameterSetName = 'Windows')] [ValidateSet (1903,1809,1803,1709,1703,1607,1511,1507)] [string]$UpdateBuild, [Parameter(ParameterSetName = 'Windows')] [ValidateSet( 'Setup Dynamic Update', 'Component Dynamic Update', 'Adobe Flash Player', 'DotNet Framework', 'Latest Cumulative Update LCU', 'Servicing Stack Update SSU')] [string]$UpdateGroup, #=================================================================================================== # 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 ) #=================================================================================================== # 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" Write-Verbose $DownloadsPath } #=================================================================================================== # CatalogOffice #=================================================================================================== if ($CatalogOffice) { $AllDownOSDUpdate = Get-OSDUpdate -CatalogOffice $CatalogOffice -OfficeProfile All -Silent if ($OfficeProfile) { $AllOSDUpdates = Get-OSDUpdate -CatalogOffice $CatalogOffice -OfficeProfile $OfficeProfile } else { $AllOSDUpdates = Get-OSDUpdate -CatalogOffice $CatalogOffice } } #=================================================================================================== # Catalog Windows #=================================================================================================== if ($CatalogWindows) { $AllDownOSDUpdate = Get-OSDUpdate -CatalogWindows $CatalogWindows $AllOSDUpdates = $AllDownOSDUpdate } #=================================================================================================== # Existing Updates #=================================================================================================== $ExistingUpdates = @() $SupersededUpdates = @() $ExistingUpdates = Get-ChildItem -Path "$DownloadsPath\*" -Directory -Recurse | Select-Object -Property * foreach ($Update in $ExistingUpdates) { if ($AllDownOSDUpdate.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" } } #=================================================================================================== # Get Downloaded Updates #=================================================================================================== foreach ($Update in $AllOSDUpdates) { if ($CatalogWindows) { $FullUpdatePath = "$RepositoryRootPath\$CatalogWindows\$($Update.Title)\$($Update.FileName)" if (Test-Path $FullUpdatePath) { $Update.OSDStatus = "Downloaded" } } } #=================================================================================================== # 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 1903) {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateBuild -eq '1903'}} 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 'Setup Dynamic Update') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateGroup -eq 'SetupDU'}} if ($UpdateGroup -eq 'Component Dynamic Update') {$AllOSDUpdates = $AllOSDUpdates | Where-Object {$_.UpdateGroup -like "ComponentDU*"}} 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 '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 #=================================================================================================== $AllOSDUpdates = $AllOSDUpdates | Select-Object -Property Catalog,OSDStatus,CreationDate,KBNumber,Title,FileName,Size,FileUri,OriginUri,OSDGuid 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 Gray #Write-Host "Update already downloaded" -ForegroundColor Gray } else { Write-Host "$($Update.Title)" -ForegroundColor Cyan Write-Host "$($Update.OriginUri)" -ForegroundColor Gray Write-Host "$DownloadDirectory\$UpdateFile" -ForegroundColor Gray Start-BitsTransfer -Source $($Update.OriginUri) -Destination "$DownloadDirectory\$UpdateFile" } } } #=================================================================================================== # AddInstallScript #=================================================================================================== if ($AddInstallScript.IsPresent) { Write-Verbose "Adding $RepositoryRootPath\Install-OSDUpdate.ps1" -Verbose Copy-Item "$($MyInvocation.MyCommand.Module.ModuleBase)\Scripts\Install-OSDUpdate.ps1" "$RepositoryRootPath" -Force | Out-Null if ($CatalogOffice) { Write-Verbose "Adding $DownloadsPath\OSDUpdate-Office.ps1" -Verbose Copy-Item "$($MyInvocation.MyCommand.Module.ModuleBase)\Scripts\OSDUpdate-Office.ps1" "$DownloadsPath" -Force | Out-Null } if ($CatalogWindows) { Write-Verbose "Adding $DownloadsPath\OSDUpdate-Windows.ps1" -Verbose Copy-Item "$($MyInvocation.MyCommand.Module.ModuleBase)\Scripts\OSDUpdate-Windows.ps1" "$DownloadsPath" -Force | Out-Null } } #=================================================================================================== } |