Public/New-OSBuild.ps1
<# .SYNOPSIS Creates a new OSBuild from an OSBuild Task .DESCRIPTION Creates a new OSBuild from an OSBuild Task created with New-OSBuildTask .LINK https://www.osdeploy.com/osbuilder/docs/functions/osbuild/new-osbuild .PARAMETER CreateISO Creates an ISO of the OSBuilder Media .PARAMETER DownloadUpdates Automatically download the required updates if they are not present in the Content\Updates directory .PARAMETER Execute Execute the Build .PARAMETER ByTaskName Task Name to Execute .PARAMETER DontUseNewestMedia Use the OSMedia specified in the Task, not the Latest .PARAMETER PromptBeforeDismount Adds a 'Press Enter to Continue' prompt before the Install.wim is dismounted .PARAMETER PromptBeforeDismountWinPE Adds a 'Press Enter to Continue' prompt before the WinPE Wims are dismounted #> function New-OSBuild { [CmdletBinding(DefaultParameterSetName='Basic')] PARAM ( [switch]$CreateISO, [switch]$DownloadUpdates, [switch]$Execute, [switch]$ShowMediaInfo, [Parameter(ParameterSetName='Advanced')] [string]$ByTaskName, [Parameter(ParameterSetName='Advanced')] [switch]$DontUseNewestMedia, [Parameter(ParameterSetName='Advanced')] [switch]$PromptBeforeDismount, [Parameter(ParameterSetName='Advanced')] [switch]$PromptBeforeDismountWinPE ) BEGIN { #Write-Host '========================================================================================' -ForegroundColor DarkGray #Write-Host "$($MyInvocation.MyCommand.Name) BEGIN" -ForegroundColor Green #=================================================================================================== Write-Verbose '19.1.1 Validate Administrator Rights' #=================================================================================================== if (!([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { Write-Warning 'OSBuilder: This function needs to be run as Administrator' Return } #=================================================================================================== Write-Verbose '19.1.1 Initialize OSBuilder' #=================================================================================================== Get-OSBuilder -CreatePaths -HideDetails #=================================================================================================== Write-Verbose '19.1.1 Update Catalogs' #=================================================================================================== if (!(Test-Path $CatalogLocal)) {$DownloadUpdates = $true} if ($DownloadUpdates.IsPresent) {Get-OSBUpdate -UpdateCatalogs -HideDetails} #=================================================================================================== Write-Verbose '19.1.1 Gather All Updates' #=================================================================================================== $CatalogsXmls = @() $ImportCatalog = @() $AllUpdates = @() $CatalogsXmls = Get-ChildItem "$OSBuilderContent\Updates" Cat*.xml -Recurse foreach ($CatalogsXml in $CatalogsXmls) { $ImportCatalog = Import-Clixml -Path "$($CatalogsXml.FullName)" $AllUpdates += $ImportCatalog } $AllUpdates = $AllUpdates | Select-Object -Property * } PROCESS { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "$($MyInvocation.MyCommand.Name) PROCESS" -ForegroundColor Green #=================================================================================================== # OSBuild Write-Verbose '19.1.1 Get-OSBuildTask' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') { if ($ByTaskName) { if (Test-Path "$OSBuilderTasks\$ByTaskName.json"){ $OSBuildTask = Get-ChildItem -Path $OSBuilderTasks "$ByTaskName.json" -File | Where-Object {$_.Name -like "*OSBuild*"} | Select-Object -Property BaseName, FullName, Length, CreationTime, LastWriteTime | Sort-Object -Property FullName } else { Write-Warning "Could not locate $OSBuilderTasks\$ByTaskName.json" Return } } else { $OSBuildTask = @() $OSBuildTask = Get-ChildItem -Path $OSBuilderTasks OSBuild*.json -File | Select-Object -Property BaseName, FullName, Length, CreationTime, LastWriteTime | Sort-Object -Property FullName $OSBuildTask = $OSBuildTask | Out-GridView -Title "OSBuilder Tasks: Select one or more Tasks to execute and press OK (Cancel to Exit)" -Passthru } if($null -eq $OSBuildTask) { Write-Warning "OSBuild Task was not selected or found . . . Exiting!" Return } } #=================================================================================================== # OSMedia Write-Verbose '19.1.1 Get-OSMedia' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia') { if ($Name) { $OSMedia = foreach ($Item in $Name) { Write-Verbose '========== Checking $Item' $ObjectProperties = @{ Name = $Item } New-Object -TypeName PSObject -Property $ObjectProperties } } else { $OSMedia = @() if ($Refresh.IsPresent) { $OSMedia = Get-OSMedia -FullDetails | Out-GridView -PassThru -Title "Select one or more OSMedia to Update (Cancel to Exit) and press OK" } else { $OSMedia = Get-OSMedia | Out-GridView -PassThru -Title "Select one or more OSMedia to Update (Cancel to Exit) and press OK" } } if ($Refresh.IsPresent) {$Execute = $true} } foreach ($Item in $OSBuildTask) { #=================================================================================================== # OSBuild Write-Verbose '19.1.1 Read Task Contents' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') { $Task = Get-Content "$($Item.FullName)" | ConvertFrom-Json $TaskName = $($Task.TaskName) $TaskVersion = $($Task.TaskVersion) $TaskType = $($Task.TaskType) $OSMediaName = $($Task.MediaName) $OSMediaPath = "$OSBuilderOSMedia\$OSMediaName" $BuildName = $($Task.BuildName) $DisableFeature = $($Task.DisableWindowsOptionalFeature) $Drivers = $($Task.AddWindowsDriver) $EnableFeature = $($Task.EnableWindowsOptionalFeature) $EnableNetFX3 = $($Task.EnableNetFX3) $ExtraFiles = $($Task.RobocopyExtraFiles) $FeaturesOnDemand = $($Task.AddFeatureOnDemand) $LanguageFeatures = $($Task.AddLanguageFeature) $LanguageInterfacePacks = $($Task.AddLanguageInterfacePack) $LanguagePacks = $($Task.AddLanguagePack) $Packages = $($Task.AddWindowsPackage) $RemoveAppx = $($Task.RemoveAppxProvisionedPackage) $RemoveCapability = $($Task.RemoveWindowsCapability) $RemovePackage = $($Task.RemoveWindowsPackage) $Scripts = $($Task.InvokeScript) $SetAllIntl = $($Task.LangSetAllIntl) $SetInputLocale = $($Task.LangSetInputLocale) $SetSKUIntlDefaults = $($Task.LangSetSKUIntlDefaults) $SetSetupUILang = $($Task.LangSetSetupUILang) $SetSysLocale = $($Task.LangSetSysLocale) $SetUILang = $($Task.LangSetUILang) $SetUILangFallback = $($Task.LangSetUILangFallback) $SetUserLocale = $($Task.LangSetUserLocale) $StartLayout = $($Task.ImportStartLayout) $Unattend = $($Task.UseWindowsUnattend) $WinPEADKPE = $($Task.WinPEAddADKPE) $WinPEADKRE = $($Task.WinPEAddADKRE) $WinPEADKSetup = $($Task.WinPEAddADKSetup) $WinPEDaRT = $($Task.WinPEAddDaRT) $WinPEDrivers = $($Task.WinPEAddWindowsDriver) $WinPEExtraFilesPE = $($Task.WinPERobocopyExtraFilesPE) $WinPEExtraFilesRE = $($Task.WinPERobocopyExtraFilesRE) $WinPEExtraFilesSetup = $($Task.WinPERobocopyExtraFilesSetup) $WinPEScriptsPE = $($Task.WinPEInvokeScriptPE) $WinPEScriptsRE = $($Task.WinPEInvokeScriptRE) $WinPEScriptsSetup = $($Task.WinPEInvokeScriptSetup) } #=================================================================================================== # OSBuild Write-Verbose '19.1.1 OSBuild Task Information' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "OSBuild Task Information" -ForegroundColor Green Write-Host "-TaskName: $TaskName" Write-Host "-TaskVersion: $TaskVersion" Write-Host "-TaskType: $TaskType" Write-Host "-OSMedia Name: $OSMediaName" Write-Host "-OSMedia Path: $OSMediaPath" Write-Host "-Build Name: $BuildName" Write-Host "-Disable Feature:" if ($DisableFeature) {foreach ($item in $DisableFeature) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-Drivers:" if ($Drivers) {foreach ($item in $Drivers) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-Enable Feature:" if ($EnableFeature) {foreach ($item in $EnableFeature) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-Enable NetFx3: $EnableNetFX3" Write-Host "-Extra Files:" if ($ExtraFiles) {foreach ($item in $ExtraFiles) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-Features On Demand:" if ($FeaturesOnDemand) {foreach ($item in $FeaturesOnDemand) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-Language Features:" if ($LanguageFeatures) {foreach ($item in $LanguageFeatures) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-Language Interface Packs:" if ($LanguageInterfacePacks) {foreach ($item in $LanguageInterfacePacks) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-Language Packs:" if ($LanguagePacks) {foreach ($item in $LanguagePacks) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-Packages:" if ($Packages) {foreach ($item in $Packages) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-Remove Appx:" if ($RemoveAppx) {foreach ($item in $RemoveAppx) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-Remove Capability:" if ($RemoveCapability) {foreach ($item in $RemoveCapability) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-Remove Packages:" if ($RemovePackage) {foreach ($item in $RemovePackage) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-Scripts:" if ($Scripts) {foreach ($item in $Scripts) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-SetAllIntl (Language): $SetAllIntl" Write-Host "-SetInputLocale (Language): $SetInputLocale" Write-Host "-SetSKUIntlDefaults (Language): $SetSKUIntlDefaults" Write-Host "-SetSetupUILang (Language): $SetSetupUILang" Write-Host "-SetSysLocale (Language): $SetSysLocale" Write-Host "-SetUILang (Language): $SetUILang" Write-Host "-SetUILangFallback (Language): $SetUILangFallback" Write-Host "-SetUserLocale (Language): $SetUserLocale" Write-Host "-Start Layout: $StartLayout" Write-Host "-Unattend: $Unattend" Write-Host "-WinPE ADK Pkgs WinPE:" if ($WinPEADKPE) {foreach ($item in $WinPEADKPE) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-WinPE ADK Pkgs WinRE:" if ($WinPEADKRE) {foreach ($item in $WinPEADKRE) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-WinPE ADK Pkgs Setup:" if ($WinPEADKSetup) {foreach ($item in $WinPEADKSetup) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-WinPE DaRT: $WinPEDaRT" Write-Host "-WinPE Drivers:" if ($WinPEDrivers) {foreach ($item in $WinPEDrivers) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-WinPE Extra Files WinPE:" if ($WinPEExtraFilesPE) {foreach ($item in $WinPEExtraFilesPE) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-WinPE Extra Files WinRE:" if ($WinPEExtraFilesRE) {foreach ($item in $WinPEExtraFilesRE) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-WinPE Extra Files Setup:" if ($WinPEExtraFilesSetup) {foreach ($item in $WinPEExtraFilesSetup){Write-Host $item -ForegroundColor DarkGray}} Write-Host "-WinPE Scripts WinPE:" if ($WinPEScriptsPE) {foreach ($item in $WinPEScriptsPE) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-WinPE Scripts WinRE:" if ($WinPEScriptsRE) {foreach ($item in $WinPEScriptsRE) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-WinPE Scripts Setup:" if ($WinPEScriptsSetup) {foreach ($item in $WinPEScriptsSetup) {Write-Host $item -ForegroundColor DarkGray}} } #=================================================================================================== # OSBuild Write-Verbose '19.1.1 Validate Proper TaskVersion' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') { if ([System.Version]$TaskVersion -lt [System.Version]"18.9.24") { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "OSBuilder Tasks need to be version 18.9.24 or newer" Write-Warning "Recreate this Task using New-OSBuildTask" Return } } #=================================================================================================== # OSBuild Write-Verbose '19.1.1 Select Latest OSMedia' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild' -and (!($DontUseNewestMedia))) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Task Source OSMedia" -ForegroundColor Green Write-Host "-OSMedia Name: $OSMediaName" Write-Host "-OSMedia Path: $OSMediaPath" Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Latest Source OSMedia" -ForegroundColor Green #$LatestSource = Get-ChildItem $OSBuilderOSMedia -Directory -filter "*$($OSMediaName.split(".")[0]).*" | Sort-Object {[int] $_.Name.Split(".")[1]} | Select-Object -Last 1 $LatestSource = Get-ChildItem $OSBuilderOSMedia -Directory -filter "*$($OSMediaName.split(".")[0]).*" | Sort-Object {[int] $(($_.Name.Split(".")[1]).Split(" ")[0])} | Select-Object -Last 1 $OSMediaName = $LatestSource.BaseName $OSMediaPath = "$OSBuilderOSMedia\$OSMediaName" Write-Host "-OSMedia Name: $OSMediaName" Write-Host "-OSMedia Path: $OSMediaPath" } #=================================================================================================== # OSBuild Write-Verbose '19.1.1 Set Proper Paths' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia') { $OSMediaPath = "$OSBuilderOSMedia\$($Item.Name)" } $OSImagePath = "$OSMediaPath\OS\sources\install.wim" if (!(Test-Path "$OSMediaPath\WindowsImage.txt")) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "$OSMediaPath is not a valid OSMedia Directory" Return } if (!(Test-Path "$OSImagePath")) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "$OSImagePath is not a valid Windows Image" Return } #=================================================================================================== Write-Verbose '19.1.1 Get Windows Image Information' #=================================================================================================== $OSImageIndex = 1 $WindowsImage = Get-WindowsImage -ImagePath "$OSImagePath" -Index $OSImageIndex | Select-Object -Property * $OSImageName = $($WindowsImage.ImageName) <# $OSImageName = $OSImageName -replace "Windows 7", "Win7" $OSImageName = $OSImageName -replace "Windows 10", "Win10" $OSImageName = $OSImageName -replace "Enterprise", "Ent" $OSImageName = $OSImageName -replace "Education", "Edu" $OSImageName = $OSImageName -replace "Virtual Desktops", "VD" $OSImageName = $OSImageName -replace " for ", " " $OSImageName = $OSImageName -replace "Workstations", "Wks" $OSImageName = $OSImageName -replace "Windows Server 2016", "Svr2016" $OSImageName = $OSImageName -replace "Windows Server 2019", "Svr2019" $OSImageName = $OSImageName -replace "ServerStandardACore", "Std Core" $OSImageName = $OSImageName -replace "ServerDatacenterACore", "DC Core" $OSImageName = $OSImageName -replace "ServerStandardCore", "Std Core" $OSImageName = $OSImageName -replace "ServerDatacenterCore", "DC Core" $OSImageName = $OSImageName -replace "ServerStandard", "Std" $OSImageName = $OSImageName -replace "ServerDatacenter", "DC" $OSImageName = $OSImageName -replace "Standard", "Std" $OSImageName = $OSImageName -replace "Datacenter", "DC" $OSImageName = $OSImageName -replace 'Desktop Experience', 'DTE' $OSImageName = $OSImageName -replace '\(', '' $OSImageName = $OSImageName -replace '\)', '' #> $OSImageDescription = $($WindowsImage.ImageDescription) $OSArchitecture = $($WindowsImage.Architecture) if ($OSArchitecture -eq '0') {$OSArchitecture = 'x86'} if ($OSArchitecture -eq '6') {$OSArchitecture = 'ia64'} if ($OSArchitecture -eq '9') {$OSArchitecture = 'x64'} if ($OSArchitecture -eq '12') {$OSArchitecture = 'x64 ARM'} $OSEditionID = $($WindowsImage.EditionId) $OSInstallationType = $($WindowsImage.InstallationType) $OSLanguages = $($WindowsImage.Languages) $OSMajorVersion = $($WindowsImage.MajorVersion) $OSBuild = $($WindowsImage.Build) $OSVersion = $($WindowsImage.Version) $OSSPBuild = $($WindowsImage.SPBuild) $OSSPLevel = $($WindowsImage.SPLevel) $OSImageBootable = $($WindowsImage.ImageBootable) $OSWIMBoot = $($WindowsImage.WIMBoot) $OSCreatedTime = $($WindowsImage.CreatedTime) $OSModifiedTime = $($WindowsImage.ModifiedTime) #=================================================================================================== Write-Verbose '19.1.1 Source OSMedia Windows Image Information' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Source OSMedia Windows Image Information" -ForegroundColor Green Write-Host "-OSMedia Path: $OSMediaPath" -ForegroundColor Yellow Write-Host "-Image File: $OSImagePath" Write-Host "-Image Index: $OSImageIndex" Write-Host "-Name: $OSImageName" Write-Host "-Description: $OSImageDescription" Write-Host "-Architecture: $OSArchitecture" Write-Host "-Edition: $OSEditionID" Write-Host "-Type: $OSInstallationType" Write-Host "-Languages: $OSLanguages" Write-Host "-Major Version: $OSMajorVersion" Write-Host "-Build: $OSBuild" Write-Host "-Version: $OSVersion" Write-Host "-SPBuild: $OSSPBuild" Write-Host "-SPLevel: $OSSPLevel" Write-Host "-Bootable: $OSImageBootable" Write-Host "-WimBoot: $OSWIMBoot" Write-Host "-Created Time: $OSCreatedTime" Write-Host "-Modified Time: $OSModifiedTime" #=================================================================================================== Write-Verbose '19.1.1 Validate Registry CurrentVersion.xml' #=================================================================================================== if (Test-Path "$OSMediaPath\info\xml\CurrentVersion.xml") { $RegCurrentVersion = Import-Clixml -Path "$OSMediaPath\info\xml\CurrentVersion.xml" $OSVersionNumber = $($RegCurrentVersion.ReleaseId) if ($OSVersionNumber -gt 1809) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "OSBuilder does not currently support this version of Windows ... Check for an updated version" } } #=================================================================================================== Write-Verbose '19.1.1 Set OSVersionNumber' #=================================================================================================== if ($null -eq $OSVersionNumber) { if ($OSBuild -eq 7601) {$OSVersionNumber = 7601} if ($OSBuild -eq 10240) {$OSVersionNumber = 1507} if ($OSBuild -eq 14393) {$OSVersionNumber = 1607} if ($OSBuild -eq 15063) {$OSVersionNumber = 1703} if ($OSBuild -eq 16299) {$OSVersionNumber = 1709} if ($OSBuild -eq 17134) {$OSVersionNumber = 1803} if ($OSBuild -eq 17763) {$OSVersionNumber = 1809} } #=================================================================================================== Write-Verbose '19.1.1 WorkingName and WorkingPath' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia' -and $Refresh.IsPresent) { $WorkingName = $($Item.Name) $WorkingPath = $OSMediaPath } elseif ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') { $WorkingName = "build$((Get-Date).ToString('mmss'))" $WorkingPath = "$OSBuilderOSBuilds\$WorkingName" } else { $WorkingName = "build$((Get-Date).ToString('mmss'))" $WorkingPath = "$OSBuilderOSMedia\$WorkingName" } if (!($Refresh.IsPresent)) { #=================================================================================================== Write-Verbose '19.1.1 Remove Existing OSMedia' #=================================================================================================== if (Test-Path $WorkingPath) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "$WorkingPath will be replaced!" } #=================================================================================================== Write-Verbose '19.1.1 Setup Updates' #=================================================================================================== $UpdateCatSetup = @() $UpdateCatSetup = $AllUpdates | Where-Object {$_.Category -eq 'Setup'} $UpdateCatSetup = $UpdateCatSetup | Where-Object {$_.KBTitle -like "*$OSVersionNumber*"} $UpdateCatSetup = $UpdateCatSetup | Where-Object {$_.KBTitle -like "*$OSArchitecture*"} if ($OSInstallationType -like "*Server*") { $UpdateCatSetup = $UpdateCatSetup | Where-Object {$_.KBTitle -like "*Server*"} } else { $UpdateCatSetup = $UpdateCatSetup | Where-Object {$_.KBTitle -notlike "*Server*"} } $UpdateCatSetup = $UpdateCatSetup | Sort-Object -Property DatePosted #=================================================================================================== Write-Verbose '19.1.1 Servicing Stack Updates' #=================================================================================================== $UpdateCatServicing = @() $UpdateCatServicing = $AllUpdates | Where-Object {$_.Category -eq 'Servicing'} $UpdateCatServicing = $UpdateCatServicing | Where-Object {$_.KBTitle -like "*$OSVersionNumber*"} $UpdateCatServicing = $UpdateCatServicing | Where-Object {$_.KBTitle -like "*$OSArchitecture*"} if ($OSInstallationType -like "*Server*") { $UpdateCatServicing = $UpdateCatServicing | Where-Object {$_.KBTitle -like "*Server*"} } else { $UpdateCatServicing = $UpdateCatServicing | Where-Object {$_.KBTitle -notlike "*Server*"} } $UpdateCatServicing = $UpdateCatServicing | Sort-Object -Property DatePosted #=================================================================================================== Write-Verbose '19.1.1 Latest Cumulative Updates' #=================================================================================================== $UpdateCatCumulative = @() $UpdateCatCumulative = $AllUpdates | Where-Object {$_.Category -eq 'Cumulative'} $UpdateCatCumulative = $UpdateCatCumulative | Where-Object {$_.KBTitle -like "*$OSVersionNumber*"} $UpdateCatCumulative = $UpdateCatCumulative | Where-Object {$_.KBTitle -like "*$OSArchitecture*"} if ($OSInstallationType -like "*Server*") { $UpdateCatCumulative = $UpdateCatCumulative | Where-Object {$_.KBTitle -like "*Server*"} } else { $UpdateCatCumulative = $UpdateCatCumulative | Where-Object {$_.KBTitle -notlike "*Server*"} } $UpdateCatCumulative = $UpdateCatCumulative | Sort-Object -Property DatePosted | Select-Object -Last 1 #$UpdateCatCumulative = $UpdateCatCumulative | Sort-Object -Property DatePosted #=================================================================================================== Write-Verbose '19.1.1 Adobe Flash Security Updates' #=================================================================================================== $UpdateCatAdobe = @() $UpdateCatAdobe = $AllUpdates | Where-Object {$_.Category -eq 'Adobe'} $UpdateCatAdobe = $UpdateCatAdobe | Where-Object {$_.KBTitle -like "*$OSVersionNumber*"} $UpdateCatAdobe = $UpdateCatAdobe | Where-Object {$_.KBTitle -like "*$OSArchitecture*"} if ($OSInstallationType -like "*Server*") { $UpdateCatAdobe = $UpdateCatAdobe | Where-Object {$_.KBTitle -like "*Server*"} } else { $UpdateCatAdobe = $UpdateCatAdobe | Where-Object {$_.KBTitle -notlike "*Server*"} } $UpdateCatAdobe = $UpdateCatAdobe | Sort-Object -Property DatePosted | Select-Object -Last 1 #=================================================================================================== Write-Verbose '19.1.1 Component Updates' #=================================================================================================== $UpdateCatComponent = @() $UpdateCatComponent = $AllUpdates | Where-Object {$_.Category -eq 'Component'} $UpdateCatComponent = $UpdateCatComponent | Where-Object {$_.KBTitle -like "*$OSVersionNumber*"} $UpdateCatComponent = $UpdateCatComponent | Where-Object {$_.KBTitle -like "*$OSArchitecture*"} if ($OSInstallationType -like "*Server*") { $UpdateCatComponent = $UpdateCatComponent | Where-Object {$_.KBTitle -like "*Server*"} } else { $UpdateCatComponent = $UpdateCatComponent | Where-Object {$_.KBTitle -notlike "*Server*"} } $UpdateCatComponent = $UpdateCatComponent | Sort-Object -Property DatePosted #=================================================================================================== Write-Verbose '19.1.1 Windows 7' #=================================================================================================== $CatalogWindows7 = @() $CatalogWindows7WinPE = @() if ($OSVersion -like "6.1.7601.*" -and $OSInstallationType -eq 'Client') { $CatalogWindows7 = $AllUpdates | Where-Object {$_.Category -like "*Windows 7*"} $CatalogWindows7 = $CatalogWindows7 | Where-Object {$_.KBTitle -like "*$OSArchitecture*"} $CatalogWindows7 = $CatalogWindows7 | Sort-Object -Property DatePosted $CatalogWindows7 = $CatalogWindows7 | Sort-Object -Property DatePosted $CatalogWindows7WinPE = $CatalogWindows7 | Where-Object {$_.Severity -eq 'WinPE'} } #=================================================================================================== Write-Verbose '19.1.1 Update Validation' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Operating System Updates to Apply" -ForegroundColor Green foreach ($Update in $UpdateCatSetup) { $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (!(Test-Path "$OSBuilderContent\Updates\*\$($Update.KBTitle)\$($Update.FileName)")) { if ($DownloadUpdates.IsPresent) { Write-Warning "Missing $($Update.KBTitle) ... Downloading" Get-OSBUpdate -FilterKBTitle "$($Update.KBTitle)" -Download -HideDetails } else { Write-Warning "Missing $($Update.KBTitle) ... Execution will be Disabled" $Execute = $false } } } foreach ($Update in $UpdateCatServicing) { $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (!(Test-Path "$OSBuilderContent\Updates\*\$($Update.KBTitle)\$($Update.FileName)")) { if ($DownloadUpdates.IsPresent) { Write-Warning "Missing $($Update.KBTitle) ... Downloading" Get-OSBUpdate -FilterKBTitle "$($Update.KBTitle)" -Download -HideDetails } else { Write-Warning "Missing $($Update.KBTitle) ... Execution will be Disabled" $Execute = $false } } } foreach ($Update in $UpdateCatCumulative) { $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (!(Test-Path "$OSBuilderContent\Updates\*\$($Update.KBTitle)\$($Update.FileName)")) { if ($DownloadUpdates.IsPresent) { Write-Warning "Missing $($Update.KBTitle) ... Downloading" Get-OSBUpdate -FilterKBTitle "$($Update.KBTitle)" -Download -HideDetails } else { Write-Warning "Missing $($Update.KBTitle) ... Execution will be Disabled" $Execute = $false } } } foreach ($Update in $UpdateCatAdobe) { $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (!(Test-Path "$OSBuilderContent\Updates\*\$($Update.KBTitle)\$($Update.FileName)")) { if ($DownloadUpdates.IsPresent) { Write-Warning "Missing $($Update.KBTitle) ... Downloading" Get-OSBUpdate -FilterKBTitle "$($Update.KBTitle)" -Download -HideDetails } else { Write-Warning "Missing $($Update.KBTitle) ... Execution will be Disabled" $Execute = $false } } } foreach ($Update in $UpdateCatComponent) { $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (!(Test-Path "$OSBuilderContent\Updates\*\$($Update.KBTitle)\$($Update.FileName)")) { if ($DownloadUpdates.IsPresent) { Write-Warning "Missing $($Update.KBTitle) ... Downloading" Get-OSBUpdate -FilterKBTitle "$($Update.KBTitle)" -Download -HideDetails } else { Write-Warning "Missing $($Update.KBTitle) ... Execution will be Disabled" $Execute = $false } } } if ($OSVersion -like "6.1.7601.*") { foreach ($Update in $CatalogWindows7) { $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (!(Test-Path "$OSBuilderContent\Updates\*\$($Update.KBTitle)\$($Update.FileName)")) { if ($DownloadUpdates.IsPresent) { Write-Warning "Missing $($Update.KBTitle) ... Downloading" Get-OSBUpdate -FilterKBTitle "$($Update.KBTitle)" -Download -HideDetails } else { Write-Warning "Missing $($Update.KBTitle) ... Execution will be Disabled" $Execute = $false } } } } } #=================================================================================================== Write-Verbose '19.1.1 Execute' #=================================================================================================== if ($Execute.IsPresent) { #=================================================================================================== Write-Verbose '19.1.1 Remove Existing WorkingPath' #=================================================================================================== if (!($Refresh.IsPresent)) { if (Test-Path $WorkingPath) { Write-Host '========================================================================================' -ForegroundColor DarkGray Remove-Item -Path "$WorkingPath" -Force -Recurse } } #=================================================================================================== Write-Verbose '19.1.1 Set Working Directories' #=================================================================================================== $Info = Join-Path $WorkingPath 'info' if (!(Test-Path "$Info")) {New-Item "$Info" -ItemType Directory -Force | Out-Null} if (!(Test-Path "$Info\json")) {New-Item "$Info\json" -ItemType Directory -Force | Out-Null} if (!(Test-Path "$Info\logs")) {New-Item "$Info\logs" -ItemType Directory -Force | Out-Null} if (!(Test-Path "$Info\xml")) {New-Item "$Info\xml" -ItemType Directory -Force | Out-Null} $OS = Join-Path $WorkingPath 'OS' if (!(Test-Path "$OS")) {New-Item "$OS" -ItemType Directory -Force | Out-Null} $WinPE = Join-Path $WorkingPath 'WinPE' if (!(Test-Path "$WinPE")) {New-Item "$WinPE" -ItemType Directory -Force | Out-Null} $PEInfo = Join-Path $WinPE 'info' if (!(Test-Path "$PEInfo")) {New-Item "$PEInfo" -ItemType Directory -Force | Out-Null} if (!(Test-Path "$PEInfo\json")) {New-Item "$PEInfo\json" -ItemType Directory -Force | Out-Null} if (!(Test-Path "$PEInfo\logs")) {New-Item "$PEInfo\logs" -ItemType Directory -Force | Out-Null} if (!(Test-Path "$PEInfo\xml")) {New-Item "$PEInfo\xml" -ItemType Directory -Force | Out-Null} #=================================================================================================== Write-Verbose '19.1.1 Set Logs' #=================================================================================================== $Logs = Join-Path $Info 'logs' $PELogs = Join-Path $PEInfo 'logs' #=================================================================================================== Write-Verbose '19.1.1 Set WimTemp' #=================================================================================================== $WimTemp = Join-Path $WorkingPath "WimTemp" if (!(Test-Path "$WimTemp")) {New-Item "$WimTemp" -ItemType Directory -Force | Out-Null} #=================================================================================================== Write-Verbose '19.1.1 Start Transcript' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray $ScriptName = $($MyInvocation.MyCommand.Name) $LogName = "$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-$ScriptName.log" Start-Transcript -Path (Join-Path "$Info\logs" $LogName) #=================================================================================================== Write-Verbose '19.1.1 Working Information' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Working Information" -ForegroundColor Green Write-Host "-WorkingName: $WorkingName" -ForegroundColor Yellow Write-Host "-WorkingPath: $WorkingPath" -ForegroundColor Yellow Write-Host "-OS: $OS" Write-Host "-WinPE: $WinPE" Write-Host "-Info: $Info" Write-Host "-Logs: $Info\logs" #=================================================================================================== Write-Verbose '19.1.1 Create Mount Directories' #=================================================================================================== $MountDirectory = Join-Path $OSBuilderContent\Mount "os$((Get-Date).ToString('mmss'))" if ( ! (Test-Path "$MountDirectory")) {New-Item "$MountDirectory" -ItemType Directory -Force | Out-Null} $MountWinPE = Join-Path $OSBuilderContent\Mount "winpe$((Get-Date).ToString('mmss'))" if ( ! (Test-Path "$MountWinPE")) {New-Item "$MountWinPE" -ItemType Directory -Force | Out-Null} $MountSetup = Join-Path $OSBuilderContent\Mount "setup$((Get-Date).ToString('mmss'))" if ( ! (Test-Path "$MountSetup")) {New-Item "$MountSetup" -ItemType Directory -Force | Out-Null} $MountWinRE = Join-Path $OSBuilderContent\Mount "winre$((Get-Date).ToString('mmss'))" if ( ! (Test-Path "$MountWinRE")) {New-Item "$MountWinRE" -ItemType Directory -Force | Out-Null} #=================================================================================================== if ($Refresh.IsPresent) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Refresh: Operating System at $WorkingPath" -ForegroundColor Green Copy-Item -Path "$OSMediaPath\WinPE\*.wim" -Destination "$WimTemp" -Exclude boot.wim -Force | Out-Null if (Test-Path "$WorkingPath\OS\sources\install.wim") { Copy-Item -Path "$WorkingPath\OS\sources\install.wim" -Destination "$WimTemp\install.wim" -Force | Out-Null Remove-Item -Path "$WorkingPath\OS\Sources\install.wim" -Force | Out-Null } if (Test-Path "$WorkingPath\OS\Sources\boot.wim") {Remove-Item -Path "$WorkingPath\OS\Sources\boot.wim" -Force | Out-Null} if (Test-Path "$WorkingPath\WinPE\boot.wim") {Remove-Item -Path "$WorkingPath\WinPE\boot.wim" -Force | Out-Null} if (Test-Path "$WorkingPath\WinPE\setup.wim") {Remove-Item -Path "$WorkingPath\WinPE\setup.wim" -Force | Out-Null} if (Test-Path "$WorkingPath\WinPE\winpe.wim") {Remove-Item -Path "$WorkingPath\WinPE\winpe.wim" -Force | Out-Null} if (Test-Path "$WorkingPath\WinPE\winre.wim") {Remove-Item -Path "$WorkingPath\WinPE\winre.wim" -Force | Out-Null} } #=================================================================================================== Write-Verbose '19.1.1 Media: Copy Operating System' #=================================================================================================== if (!($Refresh.IsPresent)) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Media: Copy Operating System to $WorkingPath" -ForegroundColor Green Copy-Item -Path "$OSMediaPath\*" -Destination "$WorkingPath" -Exclude ('*.wim','*.iso') -Recurse -Force | Out-Null if (Test-Path "$WorkingPath\ISO") {Remove-Item -Path "$WorkingPath\ISO" -Force -Recurse | Out-Null} Copy-Item -Path "$OSMediaPath\OS\sources\install.wim" -Destination "$WimTemp\install.wim" -Force | Out-Null Copy-Item -Path "$OSMediaPath\WinPE\*.wim" -Destination "$WimTemp" -Exclude boot.wim -Force | Out-Null } #=================================================================================================== Write-Verbose '19.1.1 Media: Setup Update' #=================================================================================================== if (!($Refresh.IsPresent)) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Media: Setup Update" -ForegroundColor Green if (!($null -eq $UpdateCatSetup)) { foreach ($Update in $UpdateCatSetup) { $UpdateCatSetup = $(Get-ChildItem -Path $OSBuilderContent\Updates -File -Recurse | Where-Object {$_.Name -eq $($Update.FileName)}).FullName $UpdateCatSetup if (Test-Path "$UpdateCatSetup") { expand.exe "$UpdateCatSetup" -F:*.* "$OS\Sources" } else { Write-Warning "Not Found: $UpdateCatSetup ... Skipping Update" } } } } #=================================================================================================== Write-Verbose '19.1.1 Mount WinPE' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Mount-OSBWinPE -OSMediaPath "$WorkingPath" -MountSetup "$MountSetup" -MountWinPE "$MountWinPE" -MountWinRE "$MountWinRE" #=================================================================================================== Write-Verbose '19.1.1 WinPE: Servicing Stack Update' #=================================================================================================== if (!($Refresh.IsPresent)) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE: Servicing Stack Update" -ForegroundColor Green if (!($null -eq $UpdateCatServicing)) { 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" if (Get-WindowsPackage -Path "$MountSetup" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) { Write-Warning "Setup.wim KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateServicing-KB$($Update.KBNumber)-setup.wim.log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountSetup" -PackagePath "$UpdateSSU" -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'))-UpdateServicing-KB$($Update.KBNumber)-winpe.wim.log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountWinPE" -PackagePath "$UpdateSSU" -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'))-UpdateServicing-KB$($Update.KBNumber)-winre.wim.log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountWinRE" -PackagePath "$UpdateSSU" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpdateSSU ... Skipping Update" } } } } if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') { #=================================================================================================== Write-Verbose '19.1.1 Setup WIM ADK Optional Components' # OSBuild Only #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Setup WIM ADK Optional Components" -ForegroundColor Green if ([string]::IsNullOrEmpty($WinPEADKSetup) -or [string]::IsNullOrWhiteSpace($WinPEADKSetup)) { # Do Nothing } else { foreach ($PackagePath in $WinPEADKSetup) { if ($PackagePath -like "*WinPE-NetFx*") { Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountSetup" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-setup.wim.log" | Out-Null } } $WinPEADKSetup = $WinPEADKSetup | Where-Object {$_.Name -notlike "*WinPE-NetFx*"} foreach ($PackagePath in $WinPEADKSetup) { if ($PackagePath -like "*WinPE-PowerShell*") { Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountSetup" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-setup.wim.log" | Out-Null } } $WinPEADKSetup = $WinPEADKSetup | Where-Object {$_.Name -notlike "*WinPE-PowerShell*"} foreach ($PackagePath in $WinPEADKSetup) { Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountSetup" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-setup.wim.log" | Out-Null } } #=================================================================================================== Write-Verbose '19.1.1 WinPE WIM ADK Optional Components' # OSBuild Only #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE WIM ADK Optional Components" -ForegroundColor Green if ([string]::IsNullOrEmpty($WinPEADKPE) -or [string]::IsNullOrWhiteSpace($WinPEADKPE)) { # Do Nothing } else { foreach ($PackagePath in $WinPEADKPE) { if ($PackagePath -like "*WinPE-NetFx*") { Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinPE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-winpe.wim.log" | Out-Null } } $WinPEADKPE = $WinPEADKPE | Where-Object {$_.Name -notlike "*WinPE-NetFx*"} foreach ($PackagePath in $WinPEADKPE) { if ($PackagePath -like "*WinPE-PowerShell*") { Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinPE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-winpe.wim.log" | Out-Null } } $WinPEADKPE = $WinPEADKPE | Where-Object {$_.Name -notlike "*WinPE-PowerShell*"} foreach ($PackagePath in $WinPEADKPE) { Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinPE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-winpe.wim.log" | Out-Null } } #=================================================================================================== Write-Verbose '19.1.1 WinRE WIM ADK Optional Components' # OSBuild Only #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinRE WIM ADK Optional Components" -ForegroundColor Green if ([string]::IsNullOrEmpty($WinPEADKRE) -or [string]::IsNullOrWhiteSpace($WinPEADKRE)) { # Do Nothing } else { foreach ($PackagePath in $WinPEADKRE) { if ($PackagePath -like "*WinPE-NetFx*") { Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinRE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-winre.wim.log" | Out-Null } } $WinPEADKRE = $WinPEADKRE | Where-Object {$_.Name -notlike "*WinPE-NetFx*"} foreach ($PackagePath in $WinPEADKRE) { if ($PackagePath -like "*WinPE-PowerShell*") { Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinRE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-winre.wim.log" | Out-Null } } $WinPEADKRE = $WinPEADKRE | Where-Object {$_.Name -notlike "*WinPE-PowerShell*"} foreach ($PackagePath in $WinPEADKRE) { Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor DarkGray Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountWinRE" -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage-winre.wim.log" | Out-Null } } } #=================================================================================================== Write-Verbose '19.1.1 WinPE: Latest Cumulative Update' #=================================================================================================== if (!($Refresh.IsPresent)) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE: Latest Cumulative Update" -ForegroundColor Green if (!($null -eq $UpdateCatCumulative)) { 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" #if (Get-WindowsPackage -Path "$MountSetup" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) {} $SessionsXmlSetup = "$MountSetup\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 "Setup.wim KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-setup.wim.log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountSetup" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null if (!($OSVersion -like "6.1.7601.*")) { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-setup.wim.log" Write-Verbose "$CurrentLog" Dism /Image:"$MountSetup" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" } } } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-setup.wim.log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountSetup" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null if (!($OSVersion -like "6.1.7601.*")) { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-DismCleanupImage-setup.wim.log" Write-Verbose "$CurrentLog" Dism /Image:"$MountSetup" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" } } #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.wim.log" Write-Verbose "$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.wim.log" Write-Verbose "$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.wim.log" Write-Verbose "$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.wim.log" Write-Verbose "$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.wim.log" Write-Verbose "$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.wim.log" Write-Verbose "$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.wim.log" Write-Verbose "$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.wim.log" Write-Verbose "$CurrentLog" Dism /Image:"$MountWinRE" /Cleanup-Image /StartComponentCleanup /ResetBase /LogPath:"$CurrentLog" } } } else { Write-Warning "Not Found: $UpdateLCU" } } } } #=================================================================================================== Write-Verbose '19.1.1 WinPE Windows 7 Updates' #=================================================================================================== if (!($Refresh.IsPresent)) { if ($OSVersion -like "6.1.7601.*") { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Windows 7 Updates" -ForegroundColor Green if (!($null -eq $CatalogWindows7WinPE)) { foreach ($Update in $CatalogWindows7WinPE) { $UpdateWin7WinPE = $(Get-ChildItem -Path $OSBuilderContent\Updates -Directory -Recurse | Where-Object {$_.Name -eq $($Update.KBTitle)}).FullName if (Test-Path "$UpdateWin7WinPE") { Write-Host "$UpdateWin7WinPE" if (Get-WindowsPackage -Path "$MountSetup" | Where-Object {$_.PackageName -like "*$($Update.KBNumber)*"}) { Write-Warning "Setup.wim KB$($Update.KBNumber) is already installed" } else { $CurrentLog = "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateWin7WinPE-KB$($Update.KBNumber)-setup.wim.log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountSetup" -PackagePath "$UpdateWin7WinPE" -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'))-UpdateWin7WinPE-KB$($Update.KBNumber)-winpe.wim.log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountWinPE" -PackagePath "$UpdateWin7WinPE" -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'))-UpdateWin7WinPE-KB$($Update.KBNumber)-winre.wim.log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountWinRE" -PackagePath "$UpdateWin7WinPE" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpdateWin7WinPE ... Skipping Update" } } } } } if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') { #=================================================================================================== Write-Verbose '19.1.1 WinPE DaRT' # OSBuild Only #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Microsoft DaRT" -ForegroundColor Green if ($WinPEDaRT) { if ([string]::IsNullOrEmpty($WinPEDaRT) -or [string]::IsNullOrWhiteSpace($WinPEDaRT)) {Write-Warning "Skipping WinPE DaRT"} elseif (Test-Path "$OSBuilderContent\$WinPEDaRT") { #=================================================================================================== if (Test-Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig.dat')) { Write-Host "winpe.wim: $OSBuilderContent\$WinPEDaRT" expand.exe "$OSBuilderContent\$WinPEDaRT" -F:*.* "$MountWinPE" if (Test-Path "$MountWinPE\Windows\System32\winpeshl.ini") {Remove-Item -Path "$MountWinPE\Windows\System32\winpeshl.ini" -Force} #=================================================================================================== Write-Host "setup.wim: $OSBuilderContent\$WinPEDaRT" expand.exe "$OSBuilderContent\$WinPEDaRT" -F:*.* "$MountSetup" if (Test-Path "$MountSetup\Windows\System32\winpeshl.ini") {Remove-Item -Path "$MountSetup\Windows\System32\winpeshl.ini" -Force} #=================================================================================================== Write-Host "winre.wim: $OSBuilderContent\$WinPEDaRT" expand.exe "$OSBuilderContent\$WinPEDaRT" -F:*.* "$MountWinRE" (Get-Content "$MountWinRE\Windows\System32\winpeshl.ini") | ForEach-Object {$_ -replace '-prompt','-network'} | Out-File "$MountWinRE\Windows\System32\winpeshl.ini" #=================================================================================================== Write-Verbose "winpe.wim: Copying DartConfig.dat to $MountWinPE\Windows\System32\DartConfig.dat" Copy-Item -Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig.dat') -Destination "$MountWinPE\Windows\System32\DartConfig.dat" -Force | Out-Null #=================================================================================================== Write-Verbose "setup.wim: Copying DartConfig.dat to $MountSetup\Windows\System32\DartConfig.dat" Copy-Item -Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig.dat') -Destination "$MountSetup\Windows\System32\DartConfig.dat" -Force | Out-Null #=================================================================================================== Write-Verbose "winre.wim: Copying DartConfig.dat to $MountWinRE\Windows\System32\DartConfig.dat" Copy-Item -Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig.dat') -Destination "$MountWinRE\Windows\System32\DartConfig.dat" -Force | Out-Null #=================================================================================================== } elseif (Test-Path $(Join-Path $(Split-Path $WinPEDart) 'DartConfig8.dat')) { Write-Host "winpe.wim: $OSBuilderContent\$WinPEDaRT" expand.exe "$OSBuilderContent\$WinPEDaRT" -F:*.* "$MountWinPE" if (Test-Path "$MountSetup\Windows\System32\winpeshl.ini") {Remove-Item -Path "$MountSetup\Windows\System32\winpeshl.ini" -Force} #=================================================================================================== Write-Host "setup.wim: $OSBuilderContent\$WinPEDaRT" expand.exe "$OSBuilderContent\$WinPEDaRT" -F:*.* "$MountSetup" if (Test-Path "$MountSetup\Windows\System32\winpeshl.ini") {Remove-Item -Path "$MountSetup\Windows\System32\winpeshl.ini" -Force} #=================================================================================================== Write-Host "winre.wim: $OSBuilderContent\$WinPEDaRT" expand.exe "$OSBuilderContent\$WinPEDaRT" -F:*.* "$MountWinRE" (Get-Content "$MountWinRE\Windows\System32\winpeshl.ini") | ForEach-Object {$_ -replace '-prompt','-network'} | Out-File "$MountWinRE\Windows\System32\winpeshl.ini" #=================================================================================================== Write-Verbose "winpe.wim: Copying DartConfig8.dat to $MountWinPE\Windows\System32\DartConfig.dat" Copy-Item -Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig8.dat') -Destination "$MountWinPE\Windows\System32\DartConfig.dat" -Force | Out-Null #=================================================================================================== Write-Verbose "winpe.wim: Copying DartConfig8.dat to $MountSetup\Windows\System32\DartConfig.dat" Copy-Item -Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig8.dat') -Destination "$MountSetup\Windows\System32\DartConfig.dat" -Force | Out-Null #=================================================================================================== Write-Verbose "winre.wim: Copying DartConfig8.dat to $MountWinRE\Windows\System32\DartConfig.dat" Copy-Item -Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig8.dat') -Destination "$MountWinRE\Windows\System32\DartConfig.dat" -Force | Out-Null #=================================================================================================== } #=================================================================================================== } else {Write-Warning "WinPE DaRT do not exist in $OSBuilderContent\$WinPEDart"} } #=================================================================================================== Write-Verbose '19.1.1 Extra Files' # OSBuild Only #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Setup WIM Extra Files" -ForegroundColor Green foreach ($ExtraFile in $WinPEExtraFilesSetup) {robocopy "$OSBuilderContent\$ExtraFile" "$MountSetup" *.* /e /ndl /xx /b /np /ts /tee /r:0 /w:0 /log:"$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ExtraFiles-setup.wim.log" | Out-Null} Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE WIM Extra Files" -ForegroundColor Green foreach ($ExtraFile in $WinPEExtraFilesPE) {robocopy "$OSBuilderContent\$ExtraFile" "$MountWinPE" *.* /e /ndl /xx /b /np /ts /tee /r:0 /w:0 /log:"$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ExtraFiles-winpe.wim.log" | Out-Null} Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinRE WIM Extra Files" -ForegroundColor Green foreach ($ExtraFile in $WinPEExtraFilesRE) {robocopy "$OSBuilderContent\$ExtraFile" "$MountWinRE" *.* /e /ndl /xx /b /np /ts /tee /r:0 /w:0 /log:"$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ExtraFiles-winre.wim.log" | Out-Null} #=================================================================================================== Write-Verbose '19.1.1 Drivers' # OSBuild Only #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Setup WIM Drivers" -ForegroundColor Green foreach ($WinPEDriver in $WinPEDrivers) { Write-Host "$OSBuilderContent\$WinPEDriver" -ForegroundColor DarkGray Add-WindowsDriver -Path "$MountSetup" -Driver "$OSBuilderContent\$WinPEDriver" -Recurse -ForceUnsigned -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsDriver-setup.wim.log" | Out-Null } Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE WIM Drivers" -ForegroundColor Green foreach ($WinPEDriver in $WinPEDrivers) { Write-Host "$OSBuilderContent\$WinPEDriver" -ForegroundColor DarkGray Add-WindowsDriver -Path "$MountWinPE" -Driver "$OSBuilderContent\$WinPEDriver" -Recurse -ForceUnsigned -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsDriver-winpe.wim.log" | Out-Null } Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinRE WIM Drivers" -ForegroundColor Green foreach ($WinPEDriver in $WinPEDrivers) { Write-Host "$OSBuilderContent\$WinPEDriver" -ForegroundColor DarkGray Add-WindowsDriver -Path "$MountWinRE" -Driver "$OSBuilderContent\$WinPEDriver" -Recurse -ForceUnsigned -LogPath "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsDriver-winre.wim.log" | Out-Null } #=================================================================================================== Write-Verbose '19.1.1 PowerShell Scripts' # OSBuild Only #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Setup WIM PowerShell Scripts" -ForegroundColor Green foreach ($PSWimScript in $WinPEScriptsSetup) { if (Test-Path "$OSBuilderContent\$PSWimScript") { Write-Host "Setup WIM: $OSBuilderContent\$PSWimScript" -ForegroundColor Green Invoke-Expression "& '$OSBuilderContent\$PSWimScript'" } } Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE WIM PowerShell Scripts" -ForegroundColor Green foreach ($PSWimScript in $WinPEScriptsPE) { if (Test-Path "$OSBuilderContent\$PSWimScript") { Write-Host "WinPE WIM: $OSBuilderContent\$PSWimScript" -ForegroundColor Green Invoke-Expression "& '$OSBuilderContent\$PSWimScript'" } } Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinRE WIM PowerShell Scripts" -ForegroundColor Green foreach ($PSWimScript in $WinPEScriptsRE) { if (Test-Path "$OSBuilderContent\$PSWimScript") { Write-Host "WinRE WIM: $OSBuilderContent\$PSWimScript" -ForegroundColor Green Invoke-Expression "& '$OSBuilderContent\$PSWimScript'" } } } #=================================================================================================== Write-Verbose '19.1.1 Update-OSBWinPESources' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Update-OSBWinPESources -OSMediaPath "$WorkingPath" -MountSetup "$MountSetup" #=================================================================================================== Write-Verbose '19.1.1 Export-OSBWinPEPackages' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Export-OSBWinPEPackages -OSMediaPath "$WorkingPath" -MountSetup "$MountSetup" -MountWinPE "$MountWinPE" -MountWinRE "$MountWinRE" #=================================================================================================== Write-Verbose '19.1.1 Prompt Before Dismount' #=================================================================================================== if ($PromptBeforeDismountWinPE.IsPresent){[void](Read-Host 'Press Enter to Continue')} #=================================================================================================== Write-Verbose '19.1.1 Dismount-OSBWinPE' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Dismount-OSBWinPE -OSMediaPath "$WorkingPath" -MountSetup "$MountSetup" -MountWinPE "$MountWinPE" -MountWinRE "$MountWinRE" #=================================================================================================== Write-Verbose '19.1.1 Export-OSBWinPE' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Export-OSBWinPE -OSMediaPath "$WorkingPath" -MountSetup "$MountSetup" -MountWinPE "$MountWinPE" -MountWinRE "$MountWinRE" #=================================================================================================== Write-Verbose '19.1.1 Export-OSBWinPEBootWim' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Export-OSBWinPEBootWim -OSMediaPath "$WorkingPath" #=================================================================================================== Write-Verbose '19.1.1 Export-OSBWinPEInventory' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Export-OSBWinPEInventory -OSMediaPath "$WorkingPath" #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Mount' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Mount to $MountDirectory" -ForegroundColor Green $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Mount-WindowsImage.log" Write-Verbose "$CurrentLog" Mount-WindowsImage -ImagePath "$WimTemp\install.wim" -Index 1 -Path "$MountDirectory" -LogPath "$CurrentLog" | Out-Null #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Mount Registry for UBR Information' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Mount Registry for UBR Information" -ForegroundColor Green reg LOAD 'HKLM\OSMedia' "$MountDirectory\Windows\System32\Config\SOFTWARE" | Out-Null $RegCurrentVersion = Get-ItemProperty -Path 'HKLM:\OSMedia\Microsoft\Windows NT\CurrentVersion' reg UNLOAD 'HKLM\OSMedia' | Out-Null $OSVersionNumber = $null $OSVersionNumber = $($RegCurrentVersion.ReleaseId) $RegCurrentVersionUBR = $($RegCurrentVersion.UBR) $UBR = "$OSBuild.$RegCurrentVersionUBR" $RegCurrentVersion | Out-File "$Info\CurrentVersion.txt" $RegCurrentVersion | Out-File "$WorkingPath\CurrentVersion.txt" $RegCurrentVersion | Out-File "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-CurrentVersion.txt" $RegCurrentVersion | Export-Clixml -Path "$Info\xml\CurrentVersion.xml" $RegCurrentVersion | Export-Clixml -Path "$Info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-CurrentVersion.xml" $RegCurrentVersion | ConvertTo-Json | Out-File "$Info\json\CurrentVersion.json" $RegCurrentVersion | ConvertTo-Json | Out-File "$Info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-CurrentVersion.json" #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Replace WinRE' #=================================================================================================== if (!($Refresh.IsPresent)) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Replace $MountDirectory\Windows\System32\Recovery\winre.wim" -ForegroundColor Green if (Test-Path "$MountDirectory\Windows\System32\Recovery\winre.wim") { Remove-Item -Path "$MountDirectory\Windows\System32\Recovery\winre.wim" -Force } Copy-Item -Path "$WinPE\winre.wim" -Destination "$MountDirectory\Windows\System32\Recovery\winre.wim" -Force | Out-Null $GetWindowsImage = Get-WindowsImage -ImagePath "$WinPE\winre.wim" -Index 1 | Select-Object -Property * $GetWindowsImage | Out-File "$PEInfo\winre.txt" (Get-Content "$PEInfo\winre.txt") | Where-Object {$_.Trim(" `t")} | Set-Content "$PEInfo\winre.txt" $GetWindowsImage | Out-File "$PEInfo\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-winre.wim.txt" $GetWindowsImage | Export-Clixml -Path "$PEInfo\xml\Get-WindowsImage-winre.wim.xml" $GetWindowsImage | Export-Clixml -Path "$PEInfo\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-winre.wim.xml" $GetWindowsImage | ConvertTo-Json | Out-File "$PEInfo\json\Get-WindowsImage-winre.wim.json" $GetWindowsImage | ConvertTo-Json | Out-File "$PEInfo\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-winre.wim.json" } #=================================================================================================== Write-Verbose '19.1.1 Install.wim: (SSU) Servicing Stack Update' #=================================================================================================== if (!($Refresh.IsPresent)) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: (SSU) Servicing Stack Update" -ForegroundColor Green if (!($null -eq $UpdateCatServicing)) { 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" 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'))-UpdateServicing-KB$($Update.KBNumber)-install.wim.log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateSSU" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpdateSSU" } } } } #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Component Update' #=================================================================================================== if (!($Refresh.IsPresent)) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Component Update" -ForegroundColor Green if (!($null -eq $UpdateCatComponent)) { 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" 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'))-UpdateComponent-KB$($Update.KBNumber)-install.wim.log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateComp" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpdateComp" } } } } #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Update Build Revision (Pre-Windows Updates)' #=================================================================================================== $UBRPre = $UBR Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Update Build Revision $UBRPre (Pre-Windows Updates)" -ForegroundColor Yellow #=================================================================================================== Write-Verbose '19.1.1 Install.wim: (LCU) Latest Cumulative Update' #=================================================================================================== if (!($Refresh.IsPresent)) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: (LCU) Latest Cumulative Update" -ForegroundColor Green if (!($null -eq $UpdateCatCumulative)) { 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" $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)-install.wim.log" | Out-Null } } else { $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCumulative-KB$($Update.KBNumber)-install.wim.log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateLCU" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpdateLCU" } } } } #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Registry and UBR PostInstall' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Registry and UBR PostInstall" -ForegroundColor Green reg LOAD 'HKLM\OSMedia' "$MountDirectory\Windows\System32\Config\SOFTWARE" | Out-Null $RegCurrentVersion = Get-ItemProperty -Path 'HKLM:\OSMedia\Microsoft\Windows NT\CurrentVersion' reg UNLOAD 'HKLM\OSMedia' | Out-Null $OSVersionNumber = $null $OSVersionNumber = $($RegCurrentVersion.ReleaseId) $RegCurrentVersionUBR = $($RegCurrentVersion.UBR) $UBR = "$OSBuild.$RegCurrentVersionUBR" $RegCurrentVersion | Out-File "$Info\CurrentVersion.txt" $RegCurrentVersion | Out-File "$WorkingPath\CurrentVersion.txt" $RegCurrentVersion | Out-File "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-CurrentVersion.txt" $RegCurrentVersion | Export-Clixml -Path "$Info\xml\CurrentVersion.xml" $RegCurrentVersion | Export-Clixml -Path "$Info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-CurrentVersion.xml" $RegCurrentVersion | ConvertTo-Json | Out-File "$Info\json\CurrentVersion.json" $RegCurrentVersion | ConvertTo-Json | Out-File "$Info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-CurrentVersion.json" #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Update Build Revision $UBR (Post-Windows Updates)' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Update Build Revision $UBR (Post-Windows Updates)" -ForegroundColor Yellow if (!($Refresh.IsPresent)) { #=================================================================================================== Write-Verbose '19.1.1 Install.wim: (ASU) Adobe Flash Player Security Update' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: (ASU) Adobe Flash Player Security Update" -ForegroundColor Green if (!($null -eq $UpdateCatAdobe)) { 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" 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'))-UpdateAdobe-KB$($Update.KBNumber)-install.wim.log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateASU" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpdateASU" } } } #=================================================================================================== Write-Verbose '19.1.1 Install.wim: DISM Cleanup-Image' #=================================================================================================== if ($OSVersion -like "10*") { 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" } } #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Windows 7 Updates' #=================================================================================================== if ($OSBuild -eq 7601) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Windows 7 Updates" -ForegroundColor Green if (!($null -eq $CatalogWindows7)) { 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" 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)-install.wim.log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateWin7" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpdateWin7" } } } } } #=================================================================================================== Write-Verbose '19.1.1 OSBuild Only' #=================================================================================================== if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') { #=================================================================================================== Write-Verbose '19.1.1 OSBuild Language Packs' # OSBuild Only #=================================================================================================== if ($LanguagePacks) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Language Packs" -ForegroundColor Green foreach ($Update in $LanguagePacks) { if (Test-Path "$OSBuilderContent\$Update") { Write-Host "$OSBuilderContent\$Update" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$OSBuilderContent\$Update" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-LanguagePack-install.wim.log" } else { Write-Warning "Not Found: $OSBuilderContent\$Update" } } } if ($LanguageInterfacePacks) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Language Interface Packs" -ForegroundColor Green foreach ($Update in $LanguageInterfacePacks) { if (Test-Path "$OSBuilderContent\$Update") { Write-Host "$OSBuilderContent\$Update" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$OSBuilderContent\$Update" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-LanguageInterfacePack-install.wim.log" } else { Write-Warning "Not Found: $OSBuilderContent\$Update" } } } if ($LanguageFeatures) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Language Features" -ForegroundColor Green foreach ($Update in $LanguageFeatures | Where-Object {$_ -notlike "*Speech*"}) { if (Test-Path "$OSBuilderContent\$Update") { Write-Host "$OSBuilderContent\$Update" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$OSBuilderContent\$Update" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-LanguageFeatures-install.wim.log" } } foreach ($Update in $LanguageFeatures | Where-Object {$_ -like "*TextToSpeech*"}) { if (Test-Path "$OSBuilderContent\$Update") { Write-Host "$OSBuilderContent\$Update" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$OSBuilderContent\$Update" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-LanguageFeatures-install.wim.log" } } foreach ($Update in $LanguageFeatures | Where-Object {$_ -like "*Speech*" -and $_ -notlike "*TextToSpeech*"}) { if (Test-Path "$OSBuilderContent\$Update") { Write-Host "$OSBuilderContent\$Update" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$OSBuilderContent\$Update" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-LanguageFeatures-install.wim.log" } } } #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Reapply Cumulative Update' #=================================================================================================== if ($LanguagePacks -or $LanguageInterfacePacks -or $LanguageFeatures) { #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Generating Langini' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Generating Updated Langini" -ForegroundColor Green Dism /Image:"$MountDirectory" /Gen-LangIni /Distribution:"$OS" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-gen-langini.log" #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Set Language Settings' #=================================================================================================== if ($SetAllIntl) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: SetAllIntl" -ForegroundColor Green Dism /Image:"$MountDirectory" /Set-AllIntl:"$SetAllIntl" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetAllIntl.log" } if ($SetInputLocale) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: SetInputLocale" -ForegroundColor Green Dism /Image:"$MountDirectory" /Set-InputLocale:"$SetInputLocale" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetInputLocale.log" } if ($SetSKUIntlDefaults) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: SetSKUIntlDefaults" -ForegroundColor Green Dism /Image:"$MountDirectory" /Set-SKUIntlDefaults:"$SetSKUIntlDefaults" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetSKUIntlDefaults.log" } if ($SetSetupUILang) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: SetSetupUILang" -ForegroundColor Green Dism /Image:"$MountDirectory" /Set-SetupUILang:"$SetSetupUILang" /Distribution:"$OS" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetSetupUILang.log" } if ($SetSysLocale) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: SetSysLocale" -ForegroundColor Green Dism /Image:"$MountDirectory" /Set-SysLocale:"$SetSysLocale" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetSysLocale.log" } if ($SetUILang) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: SetUILang" -ForegroundColor Green Dism /Image:"$MountDirectory" /Set-UILang:"$SetUILang" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetUILang.log" } if ($SetUILangFallback) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: SetUILangFallback" -ForegroundColor Green Dism /Image:"$MountDirectory" /Set-UILangFallback:"$SetUILangFallback" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetUILangFallback.log" } if ($SetUserLocale) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: SetUserLocale" -ForegroundColor Green Dism /Image:"$MountDirectory" /Set-UserLocale:"$SetUserLocale" /LogPath:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dism-SetUserLocale.log" } #=================================================================================================== Write-Verbose '19.1.1 Install.wim: (LCU) Latest Cumulative Update' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: LCU (Latest Cumulative Update)" -ForegroundColor Green if (!($null -eq $UpdateCatCumulative)) { 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 "install.wim: $UpdateCU" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateCU" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCatCumulative-KB$($Update.KBNumber)-install.wim.log" } else { Write-Warning "Not Found: $UpdateCU" } } } #=================================================================================================== Write-Verbose '19.1.1 Install.wim: DISM Cleanup-Image' #=================================================================================================== if ($OSVersion -like "10*") { 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" } } } #=================================================================================================== Write-Verbose '19.1.1 OSBuild Windows Optional Features' #=================================================================================================== if ($EnableFeature) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Enable Windows Optional Feature" -ForegroundColor Green foreach ($FeatureName in $EnableFeature) { Write-Host $FeatureName Enable-WindowsOptionalFeature -FeatureName $FeatureName -Path "$MountDirectory" -All -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Enable-WindowsOptionalFeature.log" | Out-Null } #=================================================================================================== Write-Verbose '19.1.1 Install.wim: (LCU) Latest Cumulative Update' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: LCU (Latest Cumulative Update)" -ForegroundColor Green if (!($null -eq $UpdateCatCumulative)) { 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 "install.wim: $UpdateCU" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateCU" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCatCumulative-KB$($Update.KBNumber)-install.wim.log" } else { Write-Warning "Not Found: $UpdateCU" } } } #=================================================================================================== Write-Verbose '19.1.1 Install.wim: DISM Cleanup-Image' #=================================================================================================== if ($OSVersion -like "10*") { 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" } } #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Windows 7 Updates' #=================================================================================================== if ($OSBuild -eq 7601) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Windows 7 Updates" -ForegroundColor Green if (!($null -eq $CatalogWindows7)) { 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" 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)-install.wim.log" Write-Verbose "$CurrentLog" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateWin7" -LogPath "$CurrentLog" | Out-Null } } else { Write-Warning "Not Found: $UpdateWin7" } } } } } #=================================================================================================== Write-Verbose '19.1.1 OSBuild EnableNetFX3' #=================================================================================================== if ($EnableNetFX3 -eq 'True') { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Enable NetFX 3.5" -ForegroundColor Green Enable-WindowsOptionalFeature -Path "$MountDirectory" -FeatureName NetFX3 -All -LimitAccess -Source "$OS\sources\sxs" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-NetFX3.log" #=================================================================================================== Write-Verbose '19.1.1 Install.wim: (LCU) Latest Cumulative Update' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: (LCU) Latest Cumulative Update" -ForegroundColor Green if (!($null -eq $UpdateCatCumulative)) { 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 "install.wim: $UpdateCU" Add-WindowsPackage -Path "$MountDirectory" -PackagePath "$UpdateCU" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-UpdateCatCumulative-KB$($Update.KBNumber)-install.wim.log" } else { Write-Warning "Not Found: $UpdateCU" } } } } #=================================================================================================== Write-Verbose '19.1.1 Remove Appx Packages' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Remove Appx Packages" -ForegroundColor Green if ($RemoveAppx) { foreach ($item in $RemoveAppx) { Write-Host $item Remove-AppxProvisionedPackage -Path "$MountDirectory" -PackageName $item -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Remove-AppxProvisionedPackage.log" | Out-Null } } #=================================================================================================== Write-Verbose '19.1.1 Remove Packages' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Remove Windows Packages" -ForegroundColor Green if ($RemovePackage) { foreach ($PackageName in $RemovePackage) { Write-Host $item Remove-WindowsPackage -Path "$MountDirectory" -PackageName $PackageName -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Remove-WindowsPackage.log" | Out-Null } } #=================================================================================================== Write-Verbose '19.1.1 Remove Capability' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Remove Windows Capability" -ForegroundColor Green if ($RemoveCapability) { foreach ($Name in $RemoveCapability) { Write-Host $Name Remove-WindowsCapability -Path "$MountDirectory" -Name $Name -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Remove-WindowsCapability.log" | Out-Null } } #=================================================================================================== Write-Verbose '19.1.1 Disable Windows Optional Feature' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Disable Windows Optional Feature" -ForegroundColor Green if ($DisableFeature) { foreach ($FeatureName in $DisableFeature) { Write-Host $FeatureName Disable-WindowsOptionalFeature -FeatureName $FeatureName -Path "$MountDirectory" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Disable-WindowsOptionalFeature.log" | Out-Null } } #=================================================================================================== Write-Verbose '19.1.1 Add Packages' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Add Packages" -ForegroundColor Green if ($Packages) { foreach ($PackagePath in $Packages) { Write-Host "$OSBuilderContent\$PackagePath" Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountDirectory" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage.log" | Out-Null } } #=================================================================================================== Write-Verbose '19.1.1 Add Drivers' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Add Drivers" -ForegroundColor Green if ($Drivers) { foreach ($Driver in $Drivers) { Write-Host "$OSBuilderContent\$Driver" Add-WindowsDriver -Driver "$OSBuilderContent\$Driver" -Recurse -Path "$MountDirectory" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsDriver.log" | Out-Null } } #=================================================================================================== Write-Verbose '19.1.1 Extra Files' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Extra Files" -ForegroundColor Green if ($ExtraFiles) { foreach ($ExtraFile in $ExtraFiles) { Write-Host "$OSBuilderContent\$ExtraFile" robocopy "$OSBuilderContent\$ExtraFile" "$MountDirectory" *.* /e /ndl /xx /b /np /ts /tee /r:0 /w:0 /log:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-ExtraFiles.log" | Out-Null } } #=================================================================================================== Write-Verbose '19.1.1 Start Layout' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Start Layout" -ForegroundColor Green if ($StartLayout) { Write-Host "$OSBuilderContent\$StartLayout" -ForegroundColor Green Copy-Item -Path "$OSBuilderContent\$StartLayout" -Destination "$MountDirectory\Users\Default\AppData\Local\Microsoft\Windows\Shell\LayoutModification.xml" -Recurse -Force | Out-Null } #=================================================================================================== Write-Verbose '19.1.1 Unattend.xml' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Unattend.xml" -ForegroundColor Green if ($Unattend) { Write-Host "$OSBuilderContent\$Unattend" -ForegroundColor Green if (!(Test-Path "$MountDirectory\Windows\Panther")) {New-Item -Path "$MountDirectory\Windows\Panther" -ItemType Directory -Force | Out-Null} Copy-Item -Path "$OSBuilderContent\$Unattend" -Destination "$MountDirectory\Windows\Panther\Unattend.xml" -Force Use-WindowsUnattend -UnattendPath "$OSBuilderContent\$Unattend" -Path "$MountDirectory" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Use-WindowsUnattend.log" | Out-Null } #=================================================================================================== Write-Verbose '19.1.1 PowerShell Scripts' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: PowerShell Scripts" -ForegroundColor Green foreach ($PSScript in $Scripts) { if (Test-Path "$OSBuilderContent\$PSScript") { Write-Host "Install WIM: $OSBuilderContent\$PSScript" -ForegroundColor Green Invoke-Expression "& '$OSBuilderContent\$PSScript'" } } } #=================================================================================================== Write-Verbose '19.1.1 Copy-OSBAutoExtraFiles' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Copy-OSBAutoExtraFiles -OSMediaPath "$WorkingPath" -MountDirectory "$MountDirectory" #=================================================================================================== Write-Verbose '19.1.1 Copy-OSBSessions' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Copy-OSBSessions -OSMediaPath "$WorkingPath" -MountDirectory "$MountDirectory" #=================================================================================================== Write-Verbose '19.1.1 Export-OSBInstallWimInventory' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Export-OSBInstallWimInventory -OSMediaPath "$WorkingPath" -MountDirectory "$MountDirectory" #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Dismount' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Dismount from $MountDirectory" -ForegroundColor Green if ($PromptBeforeDismount.IsPresent){[void](Read-Host 'Press Enter to Continue')} $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dismount-WindowsImage.log" Write-Verbose "$CurrentLog" Dismount-WindowsImage -Path "$MountDirectory" -Save -LogPath "$CurrentLog" | Out-Null #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Export' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Export to $OS\sources\install.wim" -ForegroundColor Green $CurrentLog = "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Export-WindowsImage.log" Write-Verbose "$CurrentLog" Export-WindowsImage -SourceImagePath "$WimTemp\install.wim" -SourceIndex 1 -DestinationImagePath "$OS\sources\install.wim" -LogPath "$CurrentLog" | Out-Null #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Export Configuration' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Export Configuration to $WorkingPath\WindowsImage.txt" -ForegroundColor Green $GetWindowsImage = @() $GetWindowsImage = Get-WindowsImage -ImagePath "$OS\sources\install.wim" -Index 1 | Select-Object -Property * Write-Verbose "========== SPBuild: $($GetWindowsImage.Build).$($GetWindowsImage.SPBuild)" if ($OSVersion -like "6.1*") { Write-Verbose '========== Windows 6.1' $UBR = "$($GetWindowsImage.Build).$($GetWindowsImage.SPBuild)" } Write-Verbose "========== UBR: $UBR" $GetWindowsImage | Add-Member -Type NoteProperty -Name "UBR" -Value $UBR $GetWindowsImage | Out-File "$WorkingPath\WindowsImage.txt" $GetWindowsImage | Out-File "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage.txt" $GetWindowsImage | Export-Clixml -Path "$Info\xml\Get-WindowsImage.xml" $GetWindowsImage | Export-Clixml -Path "$Info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage.xml" $GetWindowsImage | ConvertTo-Json | Out-File "$Info\json\Get-WindowsImage.json" $GetWindowsImage | ConvertTo-Json | Out-File "$Info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage.json" (Get-Content "$WorkingPath\WindowsImage.txt") | Where-Object {$_.Trim(" `t")} | Set-Content "$WorkingPath\WindowsImage.txt" #=================================================================================================== Write-Verbose '19.1.1 Install.wim: Export Content' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Install.wim: Export Content to $Info\Get-WindowsImageContent.txt" -ForegroundColor Green Get-WindowsImageContent -ImagePath "$OS\Sources\install.wim" -Index 1 | Out-File "$Info\Get-WindowsImageContent.txt" #=================================================================================================== Write-Verbose '19.1.1 UBR Validation' #=================================================================================================== if (!($Refresh.IsPresent)) { if ($UBRPre -eq $UBR) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning 'The Update Build Revision did not change after Windows Updates' Write-Warning 'There may have been an issue applying the Latest Cumulative Update if this was not expected' } if (!($UBR)) { Write-Host '========================================================================================' -ForegroundColor DarkGray $UBR = $((Get-Date).ToString('mmss')) Write-Warning 'Could not determine a UBR' } } #=================================================================================================== Write-Verbose '19.1.1 Remove Temporary Files' #=================================================================================================== if (Test-Path "$WimTemp") {Remove-Item -Path "$WimTemp" -Force -Recurse | Out-Null} if (Test-Path "$MountDirectory") {Remove-Item -Path "$MountDirectory" -Force -Recurse | Out-Null} if (Test-Path "$MountWinRE") {Remove-Item -Path "$MountWinRE" -Force -Recurse | Out-Null} if (Test-Path "$MountWinPE") {Remove-Item -Path "$MountWinPE" -Force -Recurse | Out-Null} if (Test-Path "$MountSetup") {Remove-Item -Path "$MountSetup" -Force -Recurse | Out-Null} #=================================================================================================== Write-Verbose '19.1.1 Set New Name' #=================================================================================================== $OSImageName = $($GetWindowsImage.ImageName) $OSImageName = $OSImageName -replace "Windows 7", "Win7" $OSImageName = $OSImageName -replace "Windows 10", "Win10" $OSImageName = $OSImageName -replace "Enterprise", "Ent" $OSImageName = $OSImageName -replace "Education", "Edu" $OSImageName = $OSImageName -replace "Virtual Desktops", "VD" $OSImageName = $OSImageName -replace " for ", " " $OSImageName = $OSImageName -replace "Workstations", "Wks" $OSImageName = $OSImageName -replace "Windows Server 2016", "Svr2016" $OSImageName = $OSImageName -replace "Windows Server 2019", "Svr2019" $OSImageName = $OSImageName -replace "ServerStandardACore", "Std Core" $OSImageName = $OSImageName -replace "ServerDatacenterACore", "DC Core" $OSImageName = $OSImageName -replace "ServerStandardCore", "Std Core" $OSImageName = $OSImageName -replace "ServerDatacenterCore", "DC Core" $OSImageName = $OSImageName -replace "ServerStandard", "Std" $OSImageName = $OSImageName -replace "ServerDatacenter", "DC" $OSImageName = $OSImageName -replace "Standard", "Std" $OSImageName = $OSImageName -replace "Datacenter", "DC" $OSImageName = $OSImageName -replace 'Desktop Experience', 'DTE' $OSImageName = $OSImageName -replace '\(', '' $OSImageName = $OSImageName -replace '\)', '' $OSArchitecture = $($GetWindowsImage.Architecture) if ($OSArchitecture -eq '0') {$OSArchitecture = 'x86'} if ($OSArchitecture -eq '6') {$OSArchitecture = 'ia64'} if ($OSArchitecture -eq '9') {$OSArchitecture = 'x64'} if ($OSArchitecture -eq '12') {$OSArchitecture = 'x64 ARM'} $OSBuild = $($GetWindowsImage.Build) $OSVersionNumber = $null if (Test-Path "$Info\xml\CurrentVersion.xml") { $RegCurrentVersion = Import-Clixml -Path "$Info\xml\CurrentVersion.xml" $OSVersionNumber = $($RegCurrentVersion.ReleaseId) } if ($OSBuild -eq 7601) {$OSVersionNumber = 7601} if ($OSBuild -eq 10240) {$OSVersionNumber = 1507} if ($OSBuild -eq 14393) {$OSVersionNumber = 1607} if ($OSBuild -eq 15063) {$OSVersionNumber = 1703} if ($OSBuild -eq 16299) {$OSVersionNumber = 1709} if ($OSBuild -eq 17134) {$OSVersionNumber = 1803} if ($OSBuild -eq 17763) {$OSVersionNumber = 1809} if ($null -eq $OSVersionNumber) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "Windows Image Build $OSBuild is not automatically recognized" Write-Warning "Check for an updated version of OSBuilder" if ($WorkingName -like "build*") {$NewOSMediaName = "$OSImageName $OSArchitecture"} } elseif ($OSBuild -eq 7601) { if ($WorkingName -like "build*") {$NewOSMediaName = "$OSImageName $OSArchitecture"} } else { if ($WorkingName -like "build*") {$NewOSMediaName = "$OSImageName $OSArchitecture $OSVersionNumber"} } $OSLanguages = $($GetWindowsImage.Languages) $NewOSMediaName = "$NewOSMediaName $OSLanguages" if ($($OSLanguages.count) -eq 1) {$NewOSMediaName = $NewOSMediaName.replace(' en-US', '')} if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') { if ($CustomBuildName) {$NewOSMediaName = "$CustomBuildName"} } $NewOSMediaName = "$NewOSMediaName $UBR" if ($MyInvocation.MyCommand.Name -eq 'Update-OSMedia') {$NewOSMediaPath = "$OSBuilderOSMedia\$NewOSMediaName"} if ($MyInvocation.MyCommand.Name -eq 'New-OSBuild') {$NewOSMediaPath = "$OSBuilderOSBuilds\$NewOSMediaName"} #=================================================================================================== Write-Verbose '19.1.1 Rename Build Directory' #=================================================================================================== if (!($Refresh.IsPresent)) { if (Test-Path $NewOSMediaPath) { Write-Host '========================================================================================' -ForegroundColor DarkGray $mmss = $((Get-Date).ToString('mmss')) Write-Warning 'Trying to rename the Build directory, but it already exists' Write-Warning "Appending $mmss to the directory Name" $NewOSMediaName = "$NewOSMediaName $mmss" $NewOSMediaPath = "$OSBuilderOSMedia\$NewOSMediaName" } } #=================================================================================================== Write-Verbose '19.1.1 Export Variables.xml' #=================================================================================================== Get-Variable | Select-Object -Property Name, Value | Export-Clixml "$Info\xml\Variables.xml" Get-Variable | Select-Object -Property Name, Value | ConvertTo-Json | Out-File "$Info\json\Variables.json" #=================================================================================================== Write-Verbose '19.1.1 New-OSBMediaISO' #=================================================================================================== if ($CreateISO.IsPresent) { New-OSBMediaISO -FullName "$WorkingPath" } #=================================================================================================== Write-Verbose '19.1.1 Show-OSBMediaInfo' #=================================================================================================== if ($ShowMediaInfo.IsPresent) { Show-OSBMediaInfo -FullName "$WorkingPath" } #=================================================================================================== Write-Verbose '19.1.1 Stop Transcript' #=================================================================================================== if ($Refresh.IsPresent) { Write-Host '========================================================================================' -ForegroundColor DarkGray Stop-Transcript } else { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Media: Renaming ""$WorkingPath"" to ""$NewOSMediaName""" -ForegroundColor Green Stop-Transcript Rename-Item -Path "$WorkingPath" -NewName "$NewOSMediaName" -ErrorAction Stop } } } } END { #Write-Host '========================================================================================' -ForegroundColor DarkGray #Write-Host "$($MyInvocation.MyCommand.Name) END" -ForegroundColor Green } } |