Private/OSB-Updates.ps1
function OSB-Updates-DismImageCleanup { [CmdletBinding()] PARAM () #=================================================================================================== Write-Verbose '19.1.25 Install.wim: DISM Cleanup-Image' #=================================================================================================== if ($OSMajorVersion -ne 10) {Return} Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: DISM Cleanup-Image" -ForegroundColor Green if ($(Get-WindowsCapability -Path $MountDirectory | Where-Object {$_.state -eq "*pending*"})) { Write-Warning "Cannot run WindowsImage Cleanup on a WIM with Pending Installations" } else { $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-Cleanup-Image.log" Write-Verbose "$CurrentLog" Dism /Image:"$MountDirectory" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" } } function OSB-Updates-SSU { [CmdletBinding()] PARAM () #=================================================================================================== Write-Verbose '19.1.25 Install.wim: (SSU) Servicing Stack Update' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: (SSU) Servicing Stack Update" -ForegroundColor Green foreach ($Update in $UpdateCatServicing) { $UpdateSSU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (Test-Path "$UpdateSSU") { Write-Host "$UpdateSSU" -ForegroundColor DarkGray if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) { Write-Warning "KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ServicingStack-KB$($Update.KBNumber).log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateSSU" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpdateSSU" } } } function OSB-Updates-SSUForce { [CmdletBinding()] PARAM () #=================================================================================================== Write-Verbose '19.1.25 Install.wim: (SSU) Servicing Stack Update Forced' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: (SSU) Servicing Stack Update Forced" -ForegroundColor Green foreach ($Update in $UpdateCatServicing) { $UpdateSSU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (Test-Path "$UpdateSSU") { Write-Host "$UpdateSSU" -ForegroundColor DarkGray $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ServicingStack-KB$($Update.KBNumber).log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateSSU" -LogPath "$CurrentLog" | Out-Null } else { Write-Warning "Not Found: $UpdateSSU" } } } function OSB-Updates-Component { [CmdletBinding()] PARAM () #=================================================================================================== Write-Verbose '19.1.25 Install.wim: Component Update' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Component Update" -ForegroundColor Green foreach ($Update in $UpdateCatComponent) { $UpdateComp = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (Test-Path "$UpdateComp") { Write-Host "$UpdateComp" -ForegroundColor DarkGray if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) { Write-Warning "KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Component-KB$($Update.KBNumber).log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateComp" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpdateComp" } } } function OSB-Updates-Adobe { [CmdletBinding()] PARAM () #=================================================================================================== Write-Verbose '19.1.25 Install.wim: (ASU) Adobe Flash Player Security Update' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: (ASU) Adobe Flash Player Security Update" -ForegroundColor Green foreach ($Update in $UpdateCatAdobe) { $UpdateASU = @() $UpdateASU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (Test-Path "$UpdateASU") { Write-Host "$UpdateASU" -ForegroundColor DarkGray if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) { Write-Warning "KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-AdobeFlashPlayer-KB$($Update.KBNumber).log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateASU" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpdateASU" } } } function OSB-Updates-DotNet { [CmdletBinding()] PARAM () #=================================================================================================== Write-Verbose '19.1.25 Install.wim: (NetCU) DotNet Framework Cumulative' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: (NetCU) DotNet Framework Cumulative Update" -ForegroundColor Green foreach ($Update in $UpdateCatDotNet) { $UpdateNetCU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (Test-Path "$UpdateNetCU") { Write-Host "$UpdateNetCU" -ForegroundColor DarkGray $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DotNet-KB$($Update.KBNumber).log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateNetCU" -LogPath "$CurrentLog" | Out-Null } else { Write-Warning "Not Found: $UpdateNetCU" } } } function OSB-Updates-LCU { [CmdletBinding()] PARAM () #=================================================================================================== Write-Verbose '19.1.25 Install.wim: (LCU) Latest Cumulative Update' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: LCU (Latest Cumulative Update)" -ForegroundColor Green foreach ($Update in $UpdateCatCumulative) { $UpdateLCU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (Test-Path "$UpdateLCU") { Write-Host "$UpdateLCU" -ForegroundColor DarkGray $SessionsXmlInstall = "$MountDirectory\Windows\Servicing\Sessions\Sessions.xml" if (Test-Path $SessionsXmlInstall) { [xml]$XmlDocument = Get-Content -Path $SessionsXmlInstall if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.KBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Warning "KB$($Update.KBNumber) is already installed" } else { Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateLCU" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber).log" | Out-Null } } else { $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber).log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpdateLCU" } } } function OSB-Updates-LCUForce { [CmdletBinding()] PARAM () #=================================================================================================== Write-Verbose '19.1.25 Install.wim: (LCU) Latest Cumulative Update Forced' #=================================================================================================== if ($OSMajorVersion -ne 10) {Return} Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: LCU (Latest Cumulative Update Forced)" -ForegroundColor Green foreach ($Update in $UpdateCatCumulative) { $UpdateCU = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (Test-Path "$UpdateCU") { Write-Host "$UpdateCU" -ForegroundColor DarkGray $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Cumulative-KB$($Update.KBNumber).log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateCU" -LogPath "$CurrentLog" | Out-Null } else { Write-Warning "Not Found: $UpdateCU" } } } function OSB-Updates-WinSeven { [CmdletBinding()] PARAM () #=================================================================================================== Write-Verbose '19.1.25 Install.wim: Windows 7 Updates' #=================================================================================================== if ($OSBuild -ne 7601) {Return} Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Windows 7 Updates" -ForegroundColor Green foreach ($Update in $CatalogWindows7) { $UpdateWin7 = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (Test-Path "$UpdateWin7") { Write-Host "$UpdateWin7" -ForegroundColor DarkGray if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) { Write-Warning "KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateWin7-KB$($Update.KBNumber).log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateWin7" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpdateWin7" } } } function OSB-Updates-WinServ2012R2 { [CmdletBinding()] PARAM () #=================================================================================================== Write-Verbose '19.1.28 Install.wim: Windows Server 2012 R2 x64 Updates' #=================================================================================================== if ($OSBuild -ne 9600) {Return} Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Windows Server 2012 R2 x64" -ForegroundColor Green foreach ($Update in $UpWinServ2012R2x64) { $UpWinServ2012R2x64File = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (Test-Path "$UpWinServ2012R2x64File") { Write-Host "$UpWinServ2012R2x64File" -ForegroundColor DarkGray if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) { Write-Warning "KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpWinServ2012R2x64-KB$($Update.KBNumber).log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpWinServ2012R2x64File" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpWinServ2012R2x64File" } } } |