Private/OSD-UpdatesPE.ps1
function OSD-UpdatesPE-Setup { [CmdletBinding()] PARAM () #=================================================================================================== # StartTime #=================================================================================================== $StartTime = Get-Date #=================================================================================================== # Header #=================================================================================================== Write-Host "[$(($StartTime).ToString('yyyy-MM-dd-HHmmss'))] Media: Setup Update" -ForegroundColor Green #=================================================================================================== # Execute #=================================================================================================== if (!($null -eq $OSDUpdateSetupDU)) { foreach ($Update in $OSDUpdateSetupDU) { $OSDUpdateSetupDU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -File -Recurse | Where-Object {$_.Name -eq $($Update.FileName)}).FullName $OSDUpdateSetupDU if (Test-Path "$OSDUpdateSetupDU") { expand.exe "$OSDUpdateSetupDU" -F:*.* "$OS\Sources" } else { Write-Warning "Not Found: $OSDUpdateSetupDU ... Skipping Update" } } } #=================================================================================================== # Duration #=================================================================================================== $Duration = $(Get-Date) - $StartTime Write-Host "Duration: $($Duration.ToString('mm\:ss'))" -ForegroundColor DarkGray } function OSD-UpdatesPE-Seven { [CmdletBinding()] PARAM () #=================================================================================================== # StartTime #=================================================================================================== $StartTime = Get-Date #=================================================================================================== # Header #=================================================================================================== Write-Host "[$(($StartTime).ToString('yyyy-MM-dd-HHmmss'))] Media: Seven Updates" -ForegroundColor Green #=================================================================================================== # Execute #=================================================================================================== foreach ($Update in $OSDUpdateWinSeven) { if ($Update.UpdateGroup -eq 'SSU' -or $Update.UpdateGroup -eq 'LCU') { $UpdateWinPESeven = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -Directory -Recurse | Where-Object {$_.Name -eq $($Update.Title)}).FullName if (Test-Path "$UpdateWinPESeven") { Write-Host "$UpdateWinPESeven" -ForegroundColor Gray if (Get-WindowsPackage -Path "$MountWinSE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) { Write-Warning "WinSE.wim KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateWinPESeven-KB$($Update.KBNumber)-WinSE.log" Write-Verbose "CurrentLog: $CurrentLog" Add-WindowsPackage -Path "$MountWinSE" -PackagePath "$UpdateWinPESeven" -LogPath "$CurrentLog" | Out-Null } if (Get-WindowsPackage -Path "$MountWinPE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) { Write-Warning "WinPE.wim KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateWinPESeven-KB$($Update.KBNumber)-WinPE.log" Write-Verbose "CurrentLog: $CurrentLog" Add-WindowsPackage -Path "$MountWinPE" -PackagePath "$UpdateWinPESeven" -LogPath "$CurrentLog" | Out-Null } if (Get-WindowsPackage -Path "$MountWinRE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) { Write-Warning "WinRE.wim KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateWinPESeven-KB$($Update.KBNumber)-WinRE.log" Write-Verbose "CurrentLog: $CurrentLog" Add-WindowsPackage -Path "$MountWinRE" -PackagePath "$UpdateWinPESeven" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpdateWinPESeven ... Skipping Update" } } } #=================================================================================================== # Duration #=================================================================================================== $Duration = $(Get-Date) - $StartTime Write-Host "Duration: $($Duration.ToString('mm\:ss'))" -ForegroundColor DarkGray } function OSD-UpdatesPE-SSU { [CmdletBinding()] PARAM () #=================================================================================================== # Abort #=================================================================================================== if ($OSMajorVersion -ne 10) {Return} #=================================================================================================== # StartTime #=================================================================================================== $StartTime = Get-Date #=================================================================================================== # Header #=================================================================================================== Write-Host "[$(($StartTime).ToString('yyyy-MM-dd-HHmmss'))] WinPE: (SSU) Servicing Stack Update" -ForegroundColor Green #=================================================================================================== # Parameters #=================================================================================================== if ($SkipUpdates) { Write-Warning "Skip: -SkipUpdates Parameter was used" Return } #=================================================================================================== # Execute #=================================================================================================== foreach ($Update in $OSDUpdateSSU) { $UpdateSSU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -Directory -Recurse | Where-Object {$_.Name -eq $($Update.Title)}).FullName if (Test-Path "$UpdateSSU") { Write-Host "$UpdateSSU" -ForegroundColor Gray if (Get-WindowsPackage -Path "$MountWinPE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) { Write-Warning "WinPE.wim KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ServicingStack-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-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } } if (Get-WindowsPackage -Path "$MountWinRE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) { Write-Warning "WinRE.wim KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ServicingStack-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-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } } if (Get-WindowsPackage -Path "$MountWinSE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) { Write-Warning "WinSE.wim KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ServicingStack-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-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } } } else { Write-Warning "Not Found: $UpdateSSU" } } #=================================================================================================== # Duration #=================================================================================================== $Duration = $(Get-Date) - $StartTime Write-Host "Duration: $($Duration.ToString('mm\:ss'))" -ForegroundColor DarkGray } function OSD-UpdatesPE-SSUForce { [CmdletBinding()] PARAM () #=================================================================================================== # Abort #=================================================================================================== if ($OSMajorVersion -ne 10) {Return} #=================================================================================================== # StartTime #=================================================================================================== $StartTime = Get-Date #=================================================================================================== # Header #=================================================================================================== Write-Host "[$(($StartTime).ToString('yyyy-MM-dd-HHmmss'))] WinPE: (SSU) Servicing Stack Update Forced" -ForegroundColor Green #=================================================================================================== # Parameters #=================================================================================================== if ($SkipUpdates) { Write-Warning "Skip: -SkipUpdates Parameter was used" Return } #=================================================================================================== # Execute #=================================================================================================== foreach ($Update in $OSDUpdateSSU) { $UpdateSSU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -Directory -Recurse | Where-Object {$_.Name -eq $($Update.Title)}).FullName if (Test-Path "$UpdateSSU") { Write-Host "$UpdateSSU" -ForegroundColor Gray $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ServicingStack-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-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ServicingStack-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-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ServicingStack-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-Host "$ErrorMessage" if ($ErrorMessage -like "*0x800f081e*") {Write-Warning "Update not applicable to this Operating System"} } } else { Write-Warning "Not Found: $UpdateSSU ... Skipping Update" } } #=================================================================================================== # Duration #=================================================================================================== $Duration = $(Get-Date) - $StartTime Write-Host "Duration: $($Duration.ToString('mm\:ss'))" -ForegroundColor DarkGray } function OSD-UpdatesPE-LCU { [CmdletBinding()] PARAM () #=================================================================================================== # Abort #=================================================================================================== #if ($OSMajorVersion -ne 10) {Return} #=================================================================================================== # StartTime #=================================================================================================== $StartTime = Get-Date #=================================================================================================== # Header #=================================================================================================== Write-Host "[$(($StartTime).ToString('yyyy-MM-dd-HHmmss'))] WinPE: (LCU) Latest Cumulative Update" -ForegroundColor Green #=================================================================================================== # Parameters #=================================================================================================== if ($SkipUpdates) { Write-Warning "Skip: -SkipUpdates Parameter was used" Return } <# if ($OSBuild -eq 18362) { Write-Warning "Skip: Windows 10 1903 LCU error 0x80070002" Return } #> #=================================================================================================== # Execute #=================================================================================================== foreach ($Update in $OSDUpdateLCU) { $UpdateLCU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -Directory -Recurse | Where-Object {$_.Name -eq $($Update.Title)}).FullName if (Test-Path "$UpdateLCU") { Write-Host "$UpdateLCU" -ForegroundColor Gray #if (Get-WindowsPackage -Path "$MountWinPE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {} $SessionsXmlWinPE = "$MountWinPE\Windows\Servicing\Sessions\Sessions.xml" if (Test-Path $SessionsXmlWinPE) { [xml]$XmlDocument = Get-Content -Path $SessionsXmlWinPE if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.KBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Warning "WinPE.wim KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinPE.log" Write-Verbose "CurrentLog: $CurrentLog" Add-WindowsPackage -Path "$MountWinPE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null #Dism /Image:"$MountWinPE" /Add-Package /PackagePath:"$UpdateLCU" /LogPath:"$CurrentLog" if (!($OSVersion -like "6.1.7601.*")) { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinPE.log" Write-Verbose "CurrentLog: $CurrentLog" Dism /Image:"$MountWinPE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" } } } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinPE.log" Write-Verbose "CurrentLog: $CurrentLog" Add-WindowsPackage -Path "$MountWinPE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null if (!($OSVersion -like "6.1.7601.*")) { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinPE.log" Write-Verbose "CurrentLog: $CurrentLog" Dism /Image:"$MountWinPE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" } } #if (Get-WindowsPackage -Path "$MountWinRE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {} $SessionsXmlWinRE = "$MountWinRE\Windows\Servicing\Sessions\Sessions.xml" if (Test-Path $SessionsXmlWinRE) { [xml]$XmlDocument = Get-Content -Path $SessionsXmlWinRE if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.KBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Warning "WinRE.wim KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinRE.log" Write-Verbose "CurrentLog: $CurrentLog" Add-WindowsPackage -Path "$MountWinRE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null if (!($OSVersion -like "6.1.7601.*")) { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinRE.log" Write-Verbose "CurrentLog: $CurrentLog" Dism /Image:"$MountWinRE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" } } } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinRE.log" Write-Verbose "CurrentLog: $CurrentLog" Add-WindowsPackage -Path "$MountWinRE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null if (!($OSVersion -like "6.1.7601.*")) { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinRE.log" Write-Verbose "CurrentLog: $CurrentLog" Dism /Image:"$MountWinRE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" } } #if (Get-WindowsPackage -Path "$MountWinSE" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {} $SessionsXmlSetup = "$MountWinSE\Windows\Servicing\Sessions\Sessions.xml" if (Test-Path $SessionsXmlSetup) { [xml]$XmlDocument = Get-Content -Path $SessionsXmlSetup if ($XmlDocument.Sessions.Session.Tasks.Phase.package | Where-Object {$_.Name -like "*$($Update.KBNumber)*" -and $_.targetState -eq 'Installed'}) { Write-Warning "WinSE.wim KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinSE.log" Write-Verbose "CurrentLog: $CurrentLog" Add-WindowsPackage -Path "$MountWinSE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null if (!($OSVersion -like "6.1.7601.*")) { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinSE.log" Write-Verbose "CurrentLog: $CurrentLog" Dism /Image:"$MountWinSE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" } } } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinSE.log" Write-Verbose "CurrentLog: $CurrentLog" Add-WindowsPackage -Path "$MountWinSE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null if (!($OSVersion -like "6.1.7601.*")) { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinSE.log" Write-Verbose "CurrentLog: $CurrentLog" Dism /Image:"$MountWinSE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" } } } else { Write-Warning "Not Found: $UpdateLCU" } } #=================================================================================================== # Duration #=================================================================================================== $Duration = $(Get-Date) - $StartTime Write-Host "Duration: $($Duration.ToString('mm\:ss'))" -ForegroundColor DarkGray } function OSD-UpdatesPE-LCUForce { [CmdletBinding()] PARAM () #=================================================================================================== # Abort #=================================================================================================== #if ($OSMajorVersion -ne 10) {Return} #=================================================================================================== # StartTime #=================================================================================================== $StartTime = Get-Date #=================================================================================================== # Header #=================================================================================================== Write-Host "[$(($StartTime).ToString('yyyy-MM-dd-HHmmss'))] WinPE: (LCU) Latest Cumulative Update Forced" -ForegroundColor Green #=================================================================================================== # Parameters #=================================================================================================== if ($SkipUpdates) { Write-Warning "Skip: -SkipUpdates Parameter was used" Return } <# if ($OSBuild -eq 18362) { Write-Warning "Skip: Windows 10 1903 LCU error 0x80070002" Return } #> #=================================================================================================== # Execute #=================================================================================================== if (!($null -eq $OSDUpdateLCU)) { foreach ($Update in $OSDUpdateLCU) { $UpdateLCU = $(Get-ChildItem -Path $OSDBuilderContent\OSDUpdate -Directory -Recurse | Where-Object {$_.Name -eq $($Update.Title)}).FullName if (Test-Path "$UpdateLCU") { Write-Host "$UpdateLCU" -ForegroundColor Gray $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinPE.log" Write-Verbose "CurrentLog: $CurrentLog" Add-WindowsPackage -Path "$MountWinPE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null #Dism /Image:"$MountWinPE" /Add-Package /PackagePath:"$UpdateLCU" /LogPath:"$CurrentLog" if (!($OSVersion -like "6.1.7601.*")) { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinPE.log" Write-Verbose "CurrentLog: $CurrentLog" Dism /Image:"$MountWinPE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" } $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinRE.log" Write-Verbose "CurrentLog: $CurrentLog" Add-WindowsPackage -Path "$MountWinRE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null if (!($OSVersion -like "6.1.7601.*")) { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinRE.log" Write-Verbose "CurrentLog: $CurrentLog" Dism /Image:"$MountWinRE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" } $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-WinSE.log" Write-Verbose "CurrentLog: $CurrentLog" Add-WindowsPackage -Path "$MountWinSE" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null if (!($OSVersion -like "6.1.7601.*")) { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-WinSE.log" Write-Verbose "CurrentLog: $CurrentLog" Dism /Image:"$MountWinSE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" } } else { Write-Warning "Not Found: $UpdateLCU" } } } #=================================================================================================== # Duration #=================================================================================================== $Duration = $(Get-Date) - $StartTime Write-Host "Duration: $($Duration.ToString('mm\:ss'))" -ForegroundColor DarkGray } |