Private/UpdateFunctions.ps1
#=================================================================================================== # 19.10.13 Update-AdobeOS #=================================================================================================== function Update-AdobeOS { [CmdletBinding()] Param ( [switch]$Force ) #=================================================================================================== # Abort #=================================================================================================== if ($SkipUpdates) {Return} if ($SkipUpdatesOS) {Return} if ($OSMajorVersion -ne 10) {Return} if ($null -eq $OSDUpdateAdobeSU) {Return} #=================================================================================================== # Header #=================================================================================================== Show-ActionTime if ($Force.IsPresent) { Write-Host -ForegroundColor Green "OS: (ASU) Adobe Flash Player Security Update (Forced)" } else { Write-Host -ForegroundColor Green "OS: (ASU) Adobe Flash Player Security Update" } #=================================================================================================== # Execute #=================================================================================================== foreach ($Update in $OSDUpdateAdobeSU) { $UpdateASU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName if ($null -eq $UpdateASU) {Continue} if (!(Test-Path "$UpdateASU")) {Write-Warning "Not Found: $UpdateASU"; Continue} if (!($Force.IsPresent)) { $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.FileKBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -match "$($Update.KBNumber)"}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-AdobeOS-KB$($Update.FileKBNumber).log" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateASU" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" Write-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } } } #=================================================================================================== # 19.10.12 Update-ComponentOS #=================================================================================================== function Update-ComponentOS { [CmdletBinding()] Param ( [switch]$Force ) #=================================================================================================== # Abort #=================================================================================================== if ($SkipUpdates) {Return} if ($SkipUpdatesDUC) {Return} if ($SkipUpdatesOS) {Return} if ($null -eq $OSDUpdateComponentDU) {Return} #=================================================================================================== # Header #=================================================================================================== Show-ActionTime if ($Force.IsPresent) { Write-Host -ForegroundColor Green "OS: Component Update (Forced)" } else { Write-Host -ForegroundColor Green "OS: Component Update" } #=================================================================================================== # Execute #=================================================================================================== foreach ($Update in $OSDUpdateComponentDU) { $UpdateComp = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName if ($null -eq $UpdateComp) {Continue} if (!(Test-Path "$UpdateComp")) {Write-Warning "Not Found: $UpdateComp"; Continue} if (!($Force.IsPresent)) { if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -match "$($Update.KBNumber)"}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-ComponentOS-KB$($Update.FileKBNumber).log" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateComp" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" Write-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } } } #=================================================================================================== # 19.10.12 Update-CumulativeOS #=================================================================================================== function Update-CumulativeOS { [CmdletBinding()] Param ( [switch]$Force ) #=================================================================================================== # Abort #=================================================================================================== if ($SkipUpdates) {Return} if ($SkipUpdatesOS) {Return} if ($SkipUpdatesOSLCU) {Return} if ($OSMajorVersion -ne 10) {Return} if ($null -eq $OSDUpdateLCU) {Return} #=================================================================================================== # Header #=================================================================================================== Show-ActionTime if ($Force.IsPresent) { Write-Host -ForegroundColor Green "OS: (LCU) Latest Cumulative Update (Forced)" } else { Write-Host -ForegroundColor Green "OS: (LCU) Latest Cumulative Update" } #=================================================================================================== # Execute #=================================================================================================== foreach ($Update in $OSDUpdateLCU) { $UpdateLCU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName if ($null -eq $UpdateLCU) {Continue} if (!(Test-Path "$UpdateLCU")) {Write-Warning "Not Found: $UpdateLCU"; Continue} if (!($Force.IsPresent)) { $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.FileKBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } } Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-CumulativeOS-KB$($Update.FileKBNumber).log" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" Write-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } } } #=================================================================================================== # 19.10.13 Update-CumulativePE #=================================================================================================== function Update-CumulativePE { [CmdletBinding()] Param ( [switch]$Force ) #=================================================================================================== # Abort #=================================================================================================== if ($SkipUpdates) {Return} if ($SkipUpdatesPE) {Return} if ($SkipUpdatesPELCU) {Return} if ($null -eq $OSDUpdateLCU) {Return} #=================================================================================================== # Update WinPE #=================================================================================================== if ($OSMajorVersion -ne 10) { $OSDUpdateLCU = $OSDUpdateLCU | Where-Object {$_.OSDWinPE -eq $true} if ($Force.IsPresent) {Return} } Show-ActionTime Write-Host -ForegroundColor Green "WinPE: (LCU) Latest Cumulative Update" if ($OSBuild -ge 18362) { Write-Warning "Skipping Update for this version of Windows" Return } foreach ($Update in $OSDUpdateLCU) { $UpdateLCU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName if ($null -eq $UpdateLCU) {Continue} if (!(Test-Path "$UpdateLCU")) {Write-Warning "Not Found: $UpdateSSU"; Continue} if (!($Force.IsPresent)) { $SessionsXmlInstall = "$MountWinPE\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.FileKBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } } Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-CumulativePE-KB$($Update.KBNumber)-WinPE.log" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountWinPE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" Write-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } if (!($OSVersion -like "6.1.7601.*")) { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinPE.log" Write-Verbose "CurrentLog: $CurrentLog" if ($SkipComponentCleanup) { Write-Warning "Skip: -SkipComponentCleanup Parameter was used" } else { Dism /Image:"$MountWinPE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" | Out-Null } } } #=================================================================================================== # Update WinRE #=================================================================================================== Show-ActionTime Write-Host -ForegroundColor Green "WinRE: (LCU) Latest Cumulative Update" foreach ($Update in $OSDUpdateLCU) { $UpdateLCU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName if ($null -eq $UpdateLCU) {Continue} if (!(Test-Path "$UpdateLCU")) {Write-Warning "Not Found: $UpdateSSU"; Continue} if (!($Force.IsPresent)) { $SessionsXmlInstall = "$MountWinRE\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.FileKBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } } Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-CumulativePE-KB$($Update.KBNumber)-WinRE.log" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountWinRE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" Write-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } if (!($OSVersion -like "6.1.7601.*")) { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinRE.log" Write-Verbose "CurrentLog: $CurrentLog" if ($SkipComponentCleanup) { Write-Warning "Skip: -SkipComponentCleanup Parameter was used" } else { Dism /Image:"$MountWinRE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" | Out-Null } } } if ($SkipUpdatesWinSE) {Return} #=================================================================================================== # Update WinSE #=================================================================================================== Show-ActionTime Write-Host -ForegroundColor Green "WinSE: (LCU) Latest Cumulative Update" if (($OSMajorVersion -eq 10) -and ($ReleaseId -ge 1903)) {Write-Warning 'Not adding LCU to WinSE to resolve Setup issues'; Return} foreach ($Update in $OSDUpdateLCU) { $UpdateLCU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName if ($null -eq $UpdateLCU) {Continue} if (!(Test-Path "$UpdateLCU")) {Write-Warning "Not Found: $UpdateSSU"; Continue} if (!($Force.IsPresent)) { $SessionsXmlInstall = "$MountWinSE\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.FileKBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } } Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-CumulativePE-KB$($Update.KBNumber)-WinSE.log" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountWinSE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" Write-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } if (!($OSVersion -like "6.1.7601.*")) { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinSE.log" Write-Verbose "CurrentLog: $CurrentLog" if ($SkipComponentCleanup) { Write-Warning "Skip: -SkipComponentCleanup Parameter was used" } else { Dism /Image:"$MountWinSE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" | Out-Null } } } } #=================================================================================================== # 19.10.12 Update-DotNetOS #=================================================================================================== function Update-DotNetOS { [CmdletBinding()] Param ( [switch]$Force ) #=================================================================================================== # Abort #=================================================================================================== if ($SkipUpdates) {Return} if ($SkipUpdatesOS) {Return} if ($OSMajorVersion -ne 10) {Return} if ($null -eq $OSDUpdateDotNet) {Return} #=================================================================================================== # Header #=================================================================================================== Show-ActionTime if ($Force.IsPresent) { Write-Host -ForegroundColor Green "OS: (NetCU) DotNet Framework Cumulative Update (Forced)" } else { Write-Host -ForegroundColor Green "OS: (NetCU) DotNet Framework Cumulative Update" } #=================================================================================================== # Execute DotNet #=================================================================================================== foreach ($Update in $OSDUpdateDotNet | Where-Object {$_.UpdateGroup -eq 'DotNet'}) { $UpdateNetCU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName if ($null -eq $UpdateNetCU) {Continue} if (!(Test-Path "$UpdateNetCU")) {Write-Warning "Not Found: $UpdateNetCU"; Continue} $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.FileKBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-DotNetOS-KB$($Update.FileKBNumber).log" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateNetCU" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" Write-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} if ($ErrorMessage -like "*0x8007371b*") { Write-Warning "ERROR_SXS_TRANSACTION_CLOSURE_INCOMPLETE" Write-Warning "One or more required members of the transaction are not present" Write-Warning "Since this is a DotNet Update, it is quite possible this won't install until you enable a DotNet Feature like NetFX 3.5" } } } #=================================================================================================== # Execute DotNetCU #=================================================================================================== foreach ($Update in $OSDUpdateDotNet | Where-Object {$_.UpdateGroup -eq 'DotNetCU'}) { $UpdateNetCU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName if ($null -eq $UpdateNetCU) {Continue} if (!(Test-Path "$UpdateNetCU")) {Write-Warning "Not Found: $UpdateNetCU"; Continue} if (!($Force.IsPresent)) { $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.FileKBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } } Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-DotNetOS-KB$($Update.FileKBNumber).log" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateNetCU" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" Write-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} if ($ErrorMessage -like "*0x8007371b*") { Write-Warning "ERROR_SXS_TRANSACTION_CLOSURE_INCOMPLETE" Write-Warning "One or more required members of the transaction are not present" Write-Warning "Since this is a DotNet Update, it is quite possible this won't install until you enable a DotNet Feature like NetFX 3.5" } } } } function Update-LangIniMEDIA { [CmdletBinding()] Param ( [string]$OSMediaPath ) #=================================================================================================== # Header #=================================================================================================== Show-ActionTime Write-Host -ForegroundColor Green "OS: Updating WinSE.wim with updated Lang.ini" #=================================================================================================== # Execute #=================================================================================================== $MountWinSELangIni = Join-Path $OSDBuilderContent\Mount "winselangini$((Get-Date).ToString('hhmmss'))" if (!(Test-Path "$MountWinSELangIni")) {New-Item "$MountWinSELangIni" -ItemType Directory -Force | Out-Null} $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Mount-WinSELangIni.log" Mount-WindowsImage -ImagePath "$OSMediaPath\WinPE\winse.wim" -Index 1 -Path "$MountWinSELangIni" -LogPath "$CurrentLog" | Out-Null Copy-Item -Path "$OS\Sources\lang.ini" -Destination "$MountWinSELangIni\Sources" -Force | Out-Null Start-Sleep -Seconds 10 $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dismount-WinSELangIni.log" try { Dismount-WindowsImage -Path "$MountWinSELangIni" -Save -LogPath "$CurrentLog" -ErrorAction SilentlyContinue | Out-Null } catch { Write-Warning "Could not dismount WinSE.wim ... Waiting 30 seconds ..." Start-Sleep -Seconds 30 Dismount-WindowsImage -Path "$MountWinSELangIni" -Save -LogPath "$CurrentLog" | Out-Null } if (Test-Path "$MountWinSELangIni") {Remove-Item -Path "$MountWinSELangIni" -Force -Recurse | Out-Null} Write-Host "Install.wim: Updating Boot.wim Index 2 with updated Lang.ini" $MountBootLangIni = Join-Path $OSDBuilderContent\Mount "bootlangini$((Get-Date).ToString('hhmmss'))" if (!(Test-Path "$MountBootLangIni")) {New-Item "$MountBootLangIni" -ItemType Directory -Force | Out-Null} $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Mount-BootLangIni.log" Mount-WindowsImage -ImagePath "$OS\Sources\boot.wim" -Index 2 -Path "$MountBootLangIni" -LogPath "$CurrentLog" | Out-Null Copy-Item -Path "$OS\Sources\lang.ini" -Destination "$MountBootLangIni\Sources" -Force | Out-Null Start-Sleep -Seconds 10 $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dismount-BootLangIni.log" try { Dismount-WindowsImage -Path "$MountBootLangIni" -Save -LogPath "$CurrentLog" -ErrorAction SilentlyContinue | Out-Null } catch { Write-Warning "Could not dismount Boot.wim ... Waiting 30 seconds ..." Start-Sleep -Seconds 30 Dismount-WindowsImage -Path "$MountBootLangIni" -Save -LogPath "$CurrentLog" | Out-Null } if (Test-Path "$MountBootLangIni") {Remove-Item -Path "$MountBootLangIni" -Force -Recurse | Out-Null} } #=================================================================================================== # 19.10.12 Update-OptionalOS #=================================================================================================== function Update-OptionalOS { [CmdletBinding()] Param () #=================================================================================================== # Abort #=================================================================================================== if ($ScriptName -ne 'New-OSBuild') {Return} if ($SkipUpdates) {Return} if ($SkipUpdatesOS) {Return} if ($OSMajorVersion -ne 10) {Return} if ($null -eq $OSDUpdateOptional) {Return} #=================================================================================================== # Header #=================================================================================================== Show-ActionTime Write-Host -ForegroundColor Green "OS: Optional Updates" #=================================================================================================== # Execute #=================================================================================================== foreach ($Update in $OSDUpdateOptional) { $UpdateOptional = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName if ($null -eq $UpdateOptional) {Continue} if (!(Test-Path "$UpdateOptional")) {Write-Warning "Not Found: $UpdateOptional"; Continue} if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -match "$($Update.KBNumber)"}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" } else { Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-OptionalOS-KB$($Update.FileKBNumber).log" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateOptional" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" #Write-Host "$ErrorMessage" #if ($ErrorMessage -match '800f081e') {Write-Warning "Update not applicable to this Operating System"} } } } } #=================================================================================================== # 19.10.12 Update-ServicingStackOS #=================================================================================================== function Update-ServicingStackOS { [CmdletBinding()] Param ( [switch]$Force ) #=================================================================================================== # Abort #=================================================================================================== if ($SkipUpdates) {Return} if ($SkipUpdatesOS) {Return} if ($SkipUpdatesOSSSU) {Return} if ($OSMajorVersion -ne 10) {Return} if ($null -eq $OSDUpdateSSU) {Return} #=================================================================================================== # Header #=================================================================================================== Show-ActionTime if ($Force.IsPresent) { Write-Host -ForegroundColor Green "OS: (SSU) Servicing Stack Update (Forced)" } else { Write-Host -ForegroundColor Green "OS: (SSU) Servicing Stack Update" } #=================================================================================================== # Execute #=================================================================================================== foreach ($Update in $OSDUpdateSSU) { $UpdateSSU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName if ($null -eq $UpdateSSU) {Continue} if (!(Test-Path "$UpdateSSU")) {Write-Warning "Not Found: $UpdateSSU"; Continue} if (!($Force.IsPresent)) { if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -match "$($Update.KBNumber)"}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-ServicingStackOS-KB$($Update.FileKBNumber).log" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateSSU" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" Write-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } } } #=================================================================================================== # 19.10.12 Update-ServicingStackPE #=================================================================================================== function Update-ServicingStackPE { [CmdletBinding()] Param ( [switch]$Force ) #=================================================================================================== # Abort #=================================================================================================== if ($SkipUpdates) {Return} if ($SkipUpdatesPE) {Return} if ($SkipUpdatesPESSU) {Return} #if ($OSMajorVersion -ne 10) {Return} if ($null -eq $OSDUpdateSSU) {Return} #=================================================================================================== # Update WinPE #=================================================================================================== if ($OSMajorVersion -ne 10) { $OSDUpdateSSU = $OSDUpdateSSU | Where-Object {$_.OSDWinPE -eq $true} if ($Force.IsPresent) {Return} } Show-ActionTime Write-Host -ForegroundColor Green "WinPE: (SSU) Servicing Stack Update" if ($OSBuild -ge 18362) { Write-Warning "Skipping update for this version of Windows" Return } foreach ($Update in $OSDUpdateSSU) { $UpdateSSU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName if ($null -eq $UpdateSSU) {Continue} if (!(Test-Path "$UpdateSSU")) {Write-Warning "Not Found: $UpdateSSU"; Continue} if (!($Force.IsPresent)) { if (Get-WindowsPackage -Path "$MountWinPE" | Where-Object {$_.PackageName -match "$($Update.KBNumber)"}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-ServicingStackPE-KB$($Update.KBNumber)-WinPE.log" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountWinPE" -PackagePath "$UpdateSSU" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" Write-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } } #=================================================================================================== # Update WinRE #=================================================================================================== Show-ActionTime Write-Host -ForegroundColor Green "WinRE: (SSU) Servicing Stack Update" foreach ($Update in $OSDUpdateSSU) { $UpdateSSU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName if ($null -eq $UpdateSSU) {Continue} if (!(Test-Path "$UpdateSSU")) {Write-Warning "Not Found: $UpdateSSU"; Continue} if (!($Force.IsPresent)) { if (Get-WindowsPackage -Path "$MountWinRE" | Where-Object {$_.PackageName -match "$($Update.KBNumber)"}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-ServicingStackPE-KB$($Update.KBNumber)-WinRE.log" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountWinRE" -PackagePath "$UpdateSSU" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" Write-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } } #=================================================================================================== # Update WinSE #=================================================================================================== Show-ActionTime Write-Host -ForegroundColor Green "WinSE: (SSU) Servicing Stack Update" foreach ($Update in $OSDUpdateSSU) { $UpdateSSU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName if ($null -eq $UpdateSSU) {Continue} if (!(Test-Path "$UpdateSSU")) {Write-Warning "Not Found: $UpdateSSU"; Continue} if (!($Force.IsPresent)) { if (Get-WindowsPackage -Path "$MountWinSE" | Where-Object {$_.PackageName -match "$($Update.KBNumber)"}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-ServicingStackPE-KB$($Update.KBNumber)-WinSE.log" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountWinSE" -PackagePath "$UpdateSSU" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" Write-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } } } function Update-SetupDUMEDIA { [CmdletBinding()] Param () #=================================================================================================== # Changelog #=================================================================================================== #19.10.14 Resolved issue with color for Update FileName #=================================================================================================== # Abort #=================================================================================================== if ($SkipUpdates) {Return} if ($SkipSetupDU) {Return} if ($null -eq $OSDUpdateSetupDU) {Return} #=================================================================================================== # Header #=================================================================================================== Show-ActionTime Write-Host -ForegroundColor Green "MEDIA: (SetupDU) Windows Setup Dynamic Update" #=================================================================================================== # Execute #=================================================================================================== foreach ($Update in $OSDUpdateSetupDU) { $UpdateSetupDU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName if ($null -eq $UpdateSetupDU) {Continue} if (!(Test-Path "$UpdateSetupDU")) {Write-Warning "Not Found: $UpdateSetupDU"; Continue} Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" expand.exe "$UpdateSetupDU" -F:*.* "$OS\Sources" | Out-Null } } #=================================================================================================== # 19.10.12 Update-SourcesPE #=================================================================================================== function Update-SourcesPE { [CmdletBinding()] Param ( [string]$OSMediaPath ) #=================================================================================================== # Abort #=================================================================================================== if ($SkipUpdates) {Return} if ($SkipUpdatesPE) {Return} if ($SkipUpdatesOS) {Return} if ($ReleaseId -ge 1903) {Return} #=================================================================================================== # Header #=================================================================================================== Show-ActionTime; Write-Host -ForegroundColor Green "MEDIA: Update Media Sources with WinSE.wim" #=================================================================================================== # Warning #=================================================================================================== if ($OSBuild -ge 18362) { Write-Warning "Skipping Update for this version of Windows" Return } if ($ReleaseId -ge 1903) { Write-Warning "This step is currently disabled for Windows 10 1903" Write-Warning "If this is the first time you are seeing this warning," Write-Warning "you should Update-OSMedia from Windows 10 1903 18362.30" Return } #=================================================================================================== # Execute #=================================================================================================== robocopy "$MountWinSE\sources" "$OSMediaPath\OS\sources" setup.exe /ndl /xo /xx /xl /b /np /ts /tee /r:0 /w:0 /Log+:"$OSMediaPath\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Robocopy-WinSE-MediaSources.log" | Out-Null robocopy "$MountWinSE\sources" "$OSMediaPath\OS\sources" setuphost.exe /ndl /xo /xx /xl /b /np /ts /tee /r:0 /w:0 /Log+:"$OSMediaPath\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Robocopy-WinSE-MediaSources.log" | Out-Null } #=================================================================================================== # 19.10.13 Update-WindowsSevenOS #=================================================================================================== function Update-WindowsServer2012R2OS { [CmdletBinding()] Param () #=================================================================================================== # Abort #=================================================================================================== if ($ScriptName -ne 'Update-OSMedia') {Return} if ($SkipUpdates) {Return} if ($OSMajorVersion -eq 10) {Return} if ($null -eq $OSDUpdateWinTwelveR2) {Return} #=================================================================================================== # Header #=================================================================================================== Show-ActionTime Write-Host -ForegroundColor Green "OS: Windows Server 2012 R2 Updates" $SessionsXmlInstall = "$MountDirectory\Windows\Servicing\Sessions\Sessions.xml" if (Test-Path $SessionsXmlInstall) { [xml]$XmlDocument = Get-Content -Path $SessionsXmlInstall } #=================================================================================================== # Execute #=================================================================================================== foreach ($Update in $OSDUpdateWinTwelveR2) { $UpdateTwelveR2 = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName $UpdateTwelveR2 = $UpdateTwelveR2 | Select-Object -First 1 if ($null -eq $UpdateTwelveR2) {Continue} if (!(Test-Path "$UpdateTwelveR2")) {Write-Warning "Not Found: $UpdateTwelveR2"; Continue} if (Test-Path $SessionsXmlInstall) { if ($null -eq $Update.FileKBNumber) { if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.KBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } else { if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.FileKBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } } #Get updated Sessions.xml and check again if (Test-Path $SessionsXmlInstall) { [xml]$XmlDocument = Get-Content -Path $SessionsXmlInstall } if (Test-Path $SessionsXmlInstall) { if ($null -eq $Update.FileKBNumber) { if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.KBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } else { if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.FileKBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } } if ($null -eq $Update.FileKBNumber) { $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-WindowsServer2012R2OS-KB$($Update.KBNumber).log" if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -match "$($Update.KBNumber)"}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } else { $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-WindowsServer2012R2OS-KB$($Update.FileKBNumber).log" if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -match "$($Update.FileKBNumber)"}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateTwelveR2" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" Write-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } } } #=================================================================================================== # 19.10.13 Update-WindowsSevenOS #=================================================================================================== function Update-WindowsSevenOS { [CmdletBinding()] Param () #=================================================================================================== # Abort #=================================================================================================== if ($ScriptName -ne 'Update-OSMedia') {Return} if ($SkipUpdates) {Return} if ($OSMajorVersion -eq 10) {Return} if ($null -eq $OSDUpdateWinSeven) {Return} #=================================================================================================== # Header #=================================================================================================== Show-ActionTime Write-Host -ForegroundColor Green "OS: Windows 7 Updates" $SessionsXmlInstall = "$MountDirectory\Windows\Servicing\Sessions\Sessions.xml" if (Test-Path $SessionsXmlInstall) { [xml]$XmlDocument = Get-Content -Path $SessionsXmlInstall } #=================================================================================================== # Execute #=================================================================================================== foreach ($Update in $OSDUpdateWinSeven) { $UpdateSeven = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {($_.FullName -like "*$($Update.Title)*") -and ($_.Name -match "$($Update.FileName)")}).FullName $UpdateSeven = $UpdateSeven | Select-Object -First 1 if ($null -eq $UpdateSeven) {Continue} if (!(Test-Path "$UpdateSeven")) {Write-Warning "Not Found: $UpdateSeven"; Continue} if (Test-Path $SessionsXmlInstall) { if ($null -eq $Update.FileKBNumber) { if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.KBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } else { if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.FileKBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } } #Get updated Sessions.xml and check again if (Test-Path $SessionsXmlInstall) { [xml]$XmlDocument = Get-Content -Path $SessionsXmlInstall } if (Test-Path $SessionsXmlInstall) { if ($null -eq $Update.FileKBNumber) { if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.KBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } else { if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.FileKBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } } if ($null -eq $Update.FileKBNumber) { $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-WindowsSevenOS-KB$($Update.KBNumber).log" if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -match "$($Update.KBNumber)"}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } else { $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Update-WindowsSevenOS-KB$($Update.FileKBNumber).log" if (Get-WindowsPackage -Path "$MountDirectory" | Where-Object {$_.PackageName -match "$($Update.FileKBNumber)"}) { Write-Host -ForegroundColor Gray "INSTALLED $($Update.Title) - $($Update.FileName)" Continue } } Write-Host -ForegroundColor Cyan "INSTALLING " -NoNewline Write-Host -ForegroundColor Gray "$($Update.Title) - $($Update.FileName)" Write-Verbose "CurrentLog: $CurrentLog" Try {Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateSeven" -LogPath "$CurrentLog" | Out-Null} Catch { $ErrorMessage = $_.Exception.$ErrorMessage Write-Warning "$CurrentLog" Write-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } } } |