Public/New-PEBuild.ps1
<# .SYNOPSIS Creates a new PEBuild from an PEBuild Task .DESCRIPTION Creates a new PEBuild from an PEBuild Task created with New-PEBuildTask .LINK https://www.osdeploy.com/osbuilder/docs/functions/pebuild/new-pebuild .PARAMETER CreateISO New-OSBMediaISO -FullName $FullName Creates an ISO .PARAMETER Execute Creates the PEBuild .PARAMETER PromptAfterMount Adds a 'Press Enter to Continue' prompt after WinPE is mounted .PARAMETER PromptBeforeDismount Adds a 'Press Enter to Continue' prompt before WinPE is dismounted #> function New-PEBuild { [CmdletBinding(DefaultParameterSetName='Basic')] PARAM ( [switch]$CreateISO, [switch]$Execute, [Parameter(ParameterSetName='Advanced')] [switch]$PromptAfterMount, [Parameter(ParameterSetName='Advanced')] [switch]$PromptBeforeDismount ) 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 'MDT Files' #=================================================================================================== $MDTwinpeshl = @' [LaunchApps] %SYSTEMROOT%\System32\bddrun.exe,/bootstrap '@ $DaRTwinpeshl = @' [LaunchApps] %windir%\system32\netstart.exe,-network %SYSTEMDRIVE%\sources\recovery\recenv.exe '@ $MDTUnattendPEx64 = @' <?xml version="1.0" encoding="utf-8"?> <unattend xmlns="urn:schemas-microsoft-com:unattend"> <settings pass="windowsPE"> <component name="Microsoft-Windows-Setup" processorArchitecture="amd64" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"> <Display> <ColorDepth>32</ColorDepth> <HorizontalResolution>1024</HorizontalResolution> <RefreshRate>60</RefreshRate> <VerticalResolution>768</VerticalResolution> </Display> <RunSynchronous> <RunSynchronousCommand wcm:action="add"> <Description>Lite Touch PE</Description> <Order>1</Order> <Path>wscript.exe X:\Deploy\Scripts\LiteTouch.wsf</Path> </RunSynchronousCommand> </RunSynchronous> </component> </settings> </unattend> '@ $MDTUnattendPEx86 = @' <?xml version="1.0" encoding="utf-8"?> <unattend xmlns="urn:schemas-microsoft-com:unattend"> <settings pass="windowsPE"> <component name="Microsoft-Windows-Setup" processorArchitecture="x86" publicKeyToken="31bf3856ad364e35" language="neutral" versionScope="nonSxS" xmlns:wcm="http://schemas.microsoft.com/WMIConfig/2002/State"> <Display> <ColorDepth>32</ColorDepth> <HorizontalResolution>1024</HorizontalResolution> <RefreshRate>60</RefreshRate> <VerticalResolution>768</VerticalResolution> </Display> <RunSynchronous> <RunSynchronousCommand wcm:action="add"> <Description>Lite Touch PE</Description> <Order>1</Order> <Path>wscript.exe X:\Deploy\Scripts\LiteTouch.wsf</Path> </RunSynchronousCommand> </RunSynchronous> </component> </settings> </unattend> '@ } PROCESS { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "$($MyInvocation.MyCommand.Name) PROCESS" -ForegroundColor Green #=================================================================================================== Write-Verbose '19.1.1 Select Task' #=================================================================================================== $PEBuildTask = @() $PEBuildTask = Get-ChildItem -Path $OSBuilderTasks *.json -File | Select-Object -Property BaseName, FullName, Length, CreationTime, LastWriteTime | Sort-Object -Property BaseName $PEBuildTask = $PEBuildTask | Where-Object {$_.BaseName -like "MDT*" -or $_.BaseName -like "Recovery*" -or $_.BaseName -like "WinPE*"} $PEBuildTask = $PEBuildTask | Out-GridView -Title "OSBuilder Tasks: Select one or more Tasks to execute and press OK (Cancel to Exit)" -Passthru if($null -eq $PEBuildTask) { Write-Warning "OSBuild Task was not selected or found . . . Exiting!" Return } foreach ($Item in $PEBuildTask) { #=================================================================================================== Write-Verbose '19.1.1 PEBuild Task Contents' #=================================================================================================== $Task = Get-Content "$($Item.FullName)" | ConvertFrom-Json $TaskName = $($Task.TaskName).replace('PEBuild ','') $TaskVersion = $($Task.TaskVersion) $TaskType = $($Task.TaskType) $AutoExtraFiles = $($Task.AutoExtraFiles) $OSMediaName = $($Task.MediaName) $OSMediaPath = "$OSBuilderOSMedia\$OSMediaName" $DeploymentShare = $($Task.DeploymentShare) $PEOutput = $($Task.PEOutput) $ScratchSpace = $($Task.ScratchSpace) $SourceWim = $($Task.SourceWim) $WinPEADK = $($Task.WinPEAddADK) $WinPEDaRT = $($Task.WinPEAddDaRT) $WinPEDrivers = $($Task.WinPEAddWindowsDriver) $WinPEExtraFiles = $($Task.WinPERobocopyExtraFiles) $WinPEScripts = $($Task.WinPEInvokeScript) #=================================================================================================== Write-Verbose '19.1.1 PEBuild Task Information' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "PEBuild Task Information" -ForegroundColor Green Write-Host "-TaskName: $TaskName" Write-Host "-TaskVersion: $TaskVersion" Write-Host "-TaskType: $TaskType" Write-Host "-Auto ExtraFiles: $AutoExtraFiles" Write-Host "-OSMediaName: $OSMediaName" Write-Host "-OSMediaPath: $OSMediaPath" Write-Host "-DeploymentShare: $DeploymentShare" Write-Host "-PEOutput: $PEOutput" Write-Host "-ScratchSpace: $ScratchSpace" Write-Host "-SourceWim: $SourceWim" Write-Host "-WinPEDaRT: $WinPEDaRT" Write-Host "-WinPEDrivers:" if ($WinPEDrivers) {foreach ($item in $WinPEDrivers) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-WinPE ADK Pkgs:" if ($WinPEADK) {foreach ($item in $WinPEADK) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-WinPE Extra Files:" if ($WinPEExtraFiles) {foreach ($item in $WinPEExtraFiles) {Write-Host $item -ForegroundColor DarkGray}} Write-Host "-WinPE Scripts:" if ($WinPEScripts) {foreach ($item in $WinPEScripts) {Write-Host $item -ForegroundColor DarkGray}} #=================================================================================================== Write-Verbose '19.1.1 Validate Proper TaskVersion' #=================================================================================================== if ([System.Version]$TaskVersion -lt [System.Version]"18.10.10") { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "PEBuild Tasks need to be version 18.10.10 or newer" Write-Warning "Recreate this Task using New-PEBuildTask" Return } #=================================================================================================== Write-Verbose '19.1.1 Select Latest OSMedia' #=================================================================================================== 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" #=================================================================================================== Write-Verbose '19.1.1 Set Proper Paths' #=================================================================================================== $OSSourcePath = $OSMediaPath $OSImagePath = "$OSSourcePath\OS\sources\install.wim" #=================================================================================================== 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 "-Source Path: $OSSourcePath" 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 Set DestionationName' #=================================================================================================== if ($PEOutput -eq 'Recovery') { $DestinationName = "Microsoft Windows Recovery Environment ($OSArchitecture)" } else { $DestinationName = "Microsoft Windows PE ($OSArchitecture)" } Write-Host "-Destination Name: $DestinationName" #=================================================================================================== Write-Verbose '19.1.1 Validate Registry CurrentVersion.xml' #=================================================================================================== if (Test-Path "$OSSourcePath\info\xml\CurrentVersion.xml") { $RegCurrentVersion = Import-Clixml -Path "$OSSourcePath\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 Set Working Path' #=================================================================================================== #$BuildName = "build$((Get-Date).ToString('mmss'))" $WorkingPath = "$OSBuilderPEBuilds\$Taskname" #=================================================================================================== Write-Verbose '19.1.1 Validate DeploymentShare' #=================================================================================================== if ($DeploymentShare) { if (!(Test-Path "$DeploymentShare")) { Write-Warning "MDT Deployment Share not found ... Exiting!" Return } } #=================================================================================================== Write-Verbose '19.1.1 Execute' #=================================================================================================== if ($Execute.IsPresent) { #=================================================================================================== Write-Verbose '19.1.1 Remove Existing OSMedia' #=================================================================================================== if (Test-Path $WorkingPath) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Warning "$WorkingPath exists. Contents will be replaced" Remove-Item -Path "$WorkingPath\*" -Force -Recurse | Out-Null } #=================================================================================================== 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} $Sources = "$OS\sources" if (!(Test-Path "$Sources")) {New-Item "$Sources" -ItemType Directory -Force | Out-Null} #=================================================================================================== Write-Verbose '19.1.1 Set WimTemp' #=================================================================================================== $WimTemp = Join-Path $WorkingPath "WimTemp" if (!(Test-Path "$WimTemp")) {New-Item "$WimTemp" -ItemType Directory -Force | Out-Null} $WorkingWim = "$WorkingPath\WimTemp\boot.wim" #=================================================================================================== 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 WinPE Information' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Information" -ForegroundColor Green Write-Host "-WorkingName: $TaskName" -ForegroundColor Yellow Write-Host "-WorkingPath: $WorkingPath" -ForegroundColor Yellow Write-Host "-OS: $OS" Write-Host "-Info: $Info" Write-Host "-Logs: $Info\logs" #=================================================================================================== Write-Verbose '19.1.1 Create Mount Directories' #=================================================================================================== $MountDirectory = Join-Path $OSBuilderContent\Mount "pebuild$((Get-Date).ToString('mmss'))" if ( ! (Test-Path "$MountDirectory")) {New-Item "$MountDirectory" -ItemType Directory -Force | Out-Null} #=================================================================================================== Write-Verbose '19.1.1 Copy OS' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Copying $OSSourcePath\OS to $OS" -ForegroundColor Green Copy-Item -Path "$OSSourcePath\OS\bootmgr" -Destination "$OS\bootmgr" -Force | Out-Null Copy-Item -Path "$OSSourcePath\OS\bootmgr.efi" -Destination "$OS\bootmgr.efi" -Force | Out-Null Copy-Item -Path "$OSSourcePath\OS\boot\" -Destination "$OS\boot\" -Recurse -Force | Out-Null Copy-Item -Path "$OSSourcePath\OS\efi\" -Destination "$OS\efi\" -Recurse -Force | Out-Null Dism /Export-Image /SourceImageFile:"$OSSourcePath\WinPE\$SourceWim.wim" /SourceIndex:1 /DestinationImageFile:"$WorkingWim" /DestinationName:"$DestinationName" /Bootable /CheckIntegrity #Copy-Item -Path "$OSSourcePath\WinPE\$SourceWim.wim" -Destination "$WorkingWim" -Force | Out-Null if (!(Test-Path "$Sources")) {New-Item "$Sources" -ItemType Directory -Force | Out-Null} #=================================================================================================== Write-Verbose '19.1.1 WinPE Phase: Mount' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Phase: Mount WinPE WIM" -ForegroundColor Green Mount-WindowsImage -ImagePath "$WorkingWim" -Index 1 -Path "$MountDirectory" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Mount-WindowsImage.log" if ($PromptAfterMount.IsPresent){[void](Read-Host 'Press Enter to Continue')} #=================================================================================================== Write-Verbose '19.1.1 Get Registry and UBR' #=================================================================================================== reg LOAD 'HKLM\OSMedia' "$MountDirectory\Windows\System32\Config\SOFTWARE" $RegCurrentVersion = Get-ItemProperty -Path 'HKLM:\OSMedia\Microsoft\Windows NT\CurrentVersion' reg UNLOAD 'HKLM\OSMedia' $OSVersionNumber = $null $OSVersionNumber = $($RegCurrentVersion.ReleaseId) $RegCurrentVersionUBR = $($RegCurrentVersion.UBR) $UBR = "$OSBuild.$RegCurrentVersionUBR" #=================================================================================================== Write-Verbose '19.1.1 Set-ScratchSpace' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Phase: Set-ScratchSpace" -ForegroundColor Green Dism /Image:"$MountDirectory" /Set-ScratchSpace:$ScratchSpace #=================================================================================================== Write-Verbose '19.1.1 Set-TargetPath' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Phase: Set-TargetPath" -ForegroundColor Green Dism /Image:"$MountDirectory" /Set-TargetPath:"X:\" #=================================================================================================== Write-Verbose '19.1.1 WinPE Phase: ADK Optional Components' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Phase: ADK Optional Components" -ForegroundColor Green if ([string]::IsNullOrEmpty($WinPEADK) -or [string]::IsNullOrWhiteSpace($WinPEADK)) { # Do Nothing } else { foreach ($PackagePath in $WinPEADK) { if ($PackagePath -like "*NetFx*") { Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor Green Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountDirectory" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage.log" | Out-Null } } $WinPEADK = $WinPEADK | Where-Object {$_ -notlike "*NetFx*"} foreach ($PackagePath in $WinPEADK) { if ($PackagePath -like "*WinPE-PowerShell*") { Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor Green Add-WindowsPackage -PackagePath "$OSBuilderContent\$PackagePath" -Path "$MountDirectory" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsPackage.log" | Out-Null } } $WinPEADK = $WinPEADK | Where-Object {$_ -notlike "*PowerShell*"} foreach ($PackagePath in $WinPEADK) { Write-Host "$OSBuilderContent\$PackagePath" -ForegroundColor Green 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 WinPE Phase: WinPE DaRT' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Phase: 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 "$OSBuilderContent\$WinPEDaRT" expand.exe "$OSBuilderContent\$WinPEDaRT" -F:*.* "$MountDirectory" #if (Test-Path "$MountDirectory\Windows\System32\winpeshl.ini") {Remove-Item -Path "$MountDirectory\Windows\System32\winpeshl.ini" -Force} #=================================================================================================== Write-Host "Copying DartConfig.dat to $MountDirectory\Windows\System32\DartConfig.dat" Copy-Item -Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig.dat') -Destination "$MountDirectory\Windows\System32\DartConfig.dat" -Force | Out-Null #=================================================================================================== } elseif (Test-Path $(Join-Path $(Split-Path $WinPEDart) 'DartConfig8.dat')) { Write-Host "$OSBuilderContent\$WinPEDaRT" expand.exe "$OSBuilderContent\$WinPEDaRT" -F:*.* "$MountDirectory" #if (Test-Path "$MountDirectory\Windows\System32\winpeshl.ini") {Remove-Item -Path "$MountDirectory\Windows\System32\winpeshl.ini" -Force} #=================================================================================================== Write-Host "Copying DartConfig8.dat to $MountDirectory\Windows\System32\DartConfig.dat" Copy-Item -Path $(Join-Path $(Split-Path "$OSBuilderContent\$WinPEDart") 'DartConfig8.dat') -Destination "$MountDirectory\Windows\System32\DartConfig.dat" -Force | Out-Null #=================================================================================================== } #=================================================================================================== Write-Verbose '19.1.1 WinPE Edit winpeshl.ini' #=================================================================================================== if ($PEOutput -eq 'Recovery') { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Phase: Edit winpeshl.ini" -ForegroundColor Green if (Test-Path "$MountDirectory\Windows\System32\winpeshl.ini") { Remove-Item -Path "$MountDirectory\Windows\System32\winpeshl.ini" -Force | Out-Null } $DaRTwinpeshl | Out-File "$MountDirectory\Windows\System32\winpeshl.ini" -Force } #=================================================================================================== } else {Write-Warning "WinPE DaRT do not exist in $OSBuilderContent\$WinPEDart"} } #=================================================================================================== Write-Verbose '19.1.1 WinPE Remove winpeshl.ini' #=================================================================================================== if ($PEOutput -ne 'Recovery') { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Phase: Remove winpeshl.ini" -ForegroundColor Green if (Test-Path "$MountDirectory\Windows\System32\winpeshl.ini") { Remove-Item -Path "$MountDirectory\Windows\System32\winpeshl.ini" -Force | Out-Null } } #=================================================================================================== Write-Verbose '19.1.1 Copy MDT' #=================================================================================================== if ($DeploymentShare) { $MDTwinpeshl | Out-File "$MountDirectory\Windows\System32\winpeshl.ini" -Force if ($OSArchitecture -eq 'x86') {$MDTUnattendPEx86 | Out-File "$MountDirectory\Unattend.xml" -Encoding utf8 -Force} if ($OSArchitecture -eq 'x64') {$MDTUnattendPEx64 | Out-File "$MountDirectory\Unattend.xml" -Encoding utf8 -Force} New-Item -Path "$MountDirectory\Deploy\Scripts" -ItemType Directory -Force | Out-Null New-Item -Path "$MountDirectory\Deploy\Tools\$OSArchitecture\00000409" -ItemType Directory -Force | Out-Null Copy-Item -Path "$DeploymentShare\Control\Bootstrap.ini" -Destination "$MountDirectory\Deploy\Scripts\Bootstrap.ini" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Control\LocationServer.xml" -Destination "$MountDirectory\Deploy\Scripts\LocationServer.xml" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\BDD_Welcome_ENU.xml" -Destination "$MountDirectory\Deploy\Scripts\BDD_Welcome_ENU.xml" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\BackButton.jpg" -Destination "$MountDirectory\Deploy\Scripts\BackButton.jpg" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\BackButton.png" -Destination "$MountDirectory\Deploy\Scripts\BackButton.png" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\Computer.png" -Destination "$MountDirectory\Deploy\Scripts\Computer.png" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\Credentials_ENU.xml" -Destination "$MountDirectory\Deploy\Scripts\Credentials_ENU.xml" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\Credentials_scripts.vbs" -Destination "$MountDirectory\Deploy\Scripts\Credentials_scripts.vbs" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\DeployWiz_Administrator.png" -Destination "$MountDirectory\Deploy\Scripts\DeployWiz_Administrator.png" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\FolderIcon.png" -Destination "$MountDirectory\Deploy\Scripts\FolderIcon.png" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\ItemIcon1.png" -Destination "$MountDirectory\Deploy\Scripts\ItemIcon1.png" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\LTICleanup.wsf" -Destination "$MountDirectory\Deploy\Scripts\LTICleanup.wsf" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\LTIGetFolder.wsf" -Destination "$MountDirectory\Deploy\Scripts\LTIGetFolder.wsf" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\LiteTouch.wsf" -Destination "$MountDirectory\Deploy\Scripts\LiteTouch.wsf" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\MinusIcon1.png" -Destination "$MountDirectory\Deploy\Scripts\MinusIcon1.png" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\NICSettings_Definition_ENU.xml" -Destination "$MountDirectory\Deploy\Scripts\NICSettings_Definition_ENU.xml" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\NavBar.png" -Destination "$MountDirectory\Deploy\Scripts\NavBar.png" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\PlusIcon1.png" -Destination "$MountDirectory\Deploy\Scripts\PlusIcon1.png" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\SelectItem.jpg" -Destination "$MountDirectory\Deploy\Scripts\SelectItem.jpg" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\SelectItem.png" -Destination "$MountDirectory\Deploy\Scripts\SelectItem.png" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\Summary_Definition_ENU.xml" -Destination "$MountDirectory\Deploy\Scripts\Summary_Definition_ENU.xml" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\Summary_scripts.vbs" -Destination "$MountDirectory\Deploy\Scripts\Summary_scripts.vbs" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\WelcomeBanner.jpg" -Destination "$MountDirectory\Deploy\Scripts\WelcomeBanner.jpg" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\WelcomeWiz_Background.jpg" -Destination "$MountDirectory\Deploy\Scripts\WelcomeWiz_Background.jpg" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\WelcomeWiz_Choice.vbs" -Destination "$MountDirectory\Deploy\Scripts\WelcomeWiz_Choice.vbs" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\WelcomeWiz_Choice.xml" -Destination "$MountDirectory\Deploy\Scripts\WelcomeWiz_Choice.xml" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\WelcomeWiz_DeployRoot.vbs" -Destination "$MountDirectory\Deploy\Scripts\WelcomeWiz_DeployRoot.vbs" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\WelcomeWiz_DeployRoot.xml" -Destination "$MountDirectory\Deploy\Scripts\WelcomeWiz_DeployRoot.xml" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\WelcomeWiz_Initialize.vbs" -Destination "$MountDirectory\Deploy\Scripts\WelcomeWiz_Initialize.vbs" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\WelcomeWiz_Initialize.xml" -Destination "$MountDirectory\Deploy\Scripts\WelcomeWiz_Initialize.xml" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\WizUtility.vbs" -Destination "$MountDirectory\Deploy\Scripts\WizUtility.vbs" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\Wizard.css" -Destination "$MountDirectory\Deploy\Scripts\Wizard.css" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\Wizard.hta" -Destination "$MountDirectory\Deploy\Scripts\Wizard.hta" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\Wizard.ico" -Destination "$MountDirectory\Deploy\Scripts\Wizard.ico" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\ZTIBCDUtility.vbs" -Destination "$MountDirectory\Deploy\Scripts\ZTIBCDUtility.vbs" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\ZTIConfigFile.vbs" -Destination "$MountDirectory\Deploy\Scripts\ZTIConfigFile.vbs" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\ZTIDataAccess.vbs" -Destination "$MountDirectory\Deploy\Scripts\ZTIDataAccess.vbs" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\ZTIDiskUtility.vbs" -Destination "$MountDirectory\Deploy\Scripts\ZTIDiskUtility.vbs" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\ZTIGather.wsf" -Destination "$MountDirectory\Deploy\Scripts\ZTIGather.wsf" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\ZTIGather.xml" -Destination "$MountDirectory\Deploy\Scripts\ZTIGather.xml" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\ZTINicConfig.wsf" -Destination "$MountDirectory\Deploy\Scripts\ZTINicConfig.wsf" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\ZTINicUtility.vbs" -Destination "$MountDirectory\Deploy\Scripts\ZTINicUtility.vbs" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\ZTIUtility.vbs" -Destination "$MountDirectory\Deploy\Scripts\ZTIUtility.vbs" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\btnout.png" -Destination "$MountDirectory\Deploy\Scripts\btnout.png" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\btnover.png" -Destination "$MountDirectory\Deploy\Scripts\btnover.png" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\btnsel.png" -Destination "$MountDirectory\Deploy\Scripts\btnsel.png" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\header-image.png" -Destination "$MountDirectory\Deploy\Scripts\header-image.png" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\minusico.gif" -Destination "$MountDirectory\Deploy\Scripts\minusico.gif" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Scripts\plusicon.gif" -Destination "$MountDirectory\Deploy\Scripts\plusicon.gif" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\00000409\tsres.dll" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\00000409\tsres.dll" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\BDDRUN.exe" -Destination "$MountDirectory\Windows\system32\BDDRUN.exe" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\BGInfo.exe" -Destination "$MountDirectory\Windows\system32\BGInfo.exe" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\BGInfo64.exe" -Destination "$MountDirectory\Windows\system32\BGInfo64.exe" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\CcmCore.dll" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\CcmCore.dll" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\CcmUtilLib.dll" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\CcmUtilLib.dll" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\Microsoft.BDD.Utility.dll" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\Microsoft.BDD.Utility.dll" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\SmsCore.dll" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\SmsCore.dll" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\Smsboot.exe" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\Smsboot.exe" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\TSEnv.exe" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\TSEnv.exe" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\TSResNlc.dll" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\TSResNlc.dll" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\TsCore.dll" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\TsCore.dll" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\TsManager.exe" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\TsManager.exe" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\TsMessaging.dll" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\TsMessaging.dll" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\TsProgressUI.exe" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\TsProgressUI.exe" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\TsmBootstrap.exe" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\TsmBootstrap.exe" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\WinRERUN.exe" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\WinRERUN.exe" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\xprslib.dll" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\xprslib.dll" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\CommonUtils.dll" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\CommonUtils.dll" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\ccmgencert.dll" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\ccmgencert.dll" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\msvcp120.dll" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\msvcp120.dll" -Force -ErrorAction SilentlyContinue | Out-Null Copy-Item -Path "$DeploymentShare\Tools\$OSArchitecture\msvcr120.dll" -Destination "$MountDirectory\Deploy\Tools\$OSArchitecture\msvcr120.dll" -Force -ErrorAction SilentlyContinue | Out-Null #[void](Read-Host 'Press Enter to Continue') } #=================================================================================================== Write-Verbose '19.1.1 WinPE Phase: Auto Extra Files' #=================================================================================================== if ($AutoExtraFiles -eq $true) { Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Phase: Auto ExtraFiles" -ForegroundColor Green robocopy "$OSSourcePath\WinPE\AutoExtraFiles" "$MountDirectory" *.* /e /ndl /xf bcp47*.dll /xx /b /np /ts /tee /r:0 /w:0 /log:"$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-AutoExtraFiles.log" | Out-Null } #=================================================================================================== Write-Verbose '19.1.1 WinPE Phase: Extra Files' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Phase: Extra Files" -ForegroundColor Green foreach ($ExtraFile in $WinPEExtraFiles) {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 WinPE Phase: Drivers' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Phase: Drivers" -ForegroundColor Green foreach ($WinPEDriver in $WinPEDrivers) { Write-Host "$OSBuilderContent\$WinPEDriver" -ForegroundColor Green Add-WindowsDriver -Path "$MountDirectory" -Driver "$OSBuilderContent\$WinPEDriver" -Recurse -ForceUnsigned -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Add-WindowsDriver.log" | Out-Null } #=================================================================================================== Write-Verbose '19.1.1 WinPE Phase: PowerShell Scripts' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Phase: PowerShell Scripts" -ForegroundColor Green foreach ($PSWimScript in $WinPEScripts) { if (Test-Path "$OSBuilderContent\$PSWimScript") { Write-Host "$OSBuilderContent\$PSWimScript" -ForegroundColor Green Invoke-Expression "& '$OSBuilderContent\$PSWimScript'" } } #=================================================================================================== Write-Verbose '19.1.1 WinPE Mounted Package Inventory' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Phase: Export Package Inventory" -ForegroundColor Green Write-Host "$Info\WindowsPackage.txt" $GetWindowsPackage = Get-WindowsPackage -Path "$MountDirectory" $GetWindowsPackage | Out-File "$Info\WindowsPackage.txt" $GetWindowsPackage | Out-File "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsPackage.txt" $GetWindowsPackage | Export-Clixml -Path "$Info\xml\Get-WindowsPackage.xml" $GetWindowsPackage | Export-Clixml -Path "$Info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsPackage.xml" $GetWindowsPackage | ConvertTo-Json | Out-File "$Info\json\Get-WindowsPackage.json" $GetWindowsPackage | ConvertTo-Json | Out-File "$Info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsPackage.json" #=================================================================================================== Write-Verbose '19.1.1 WinPE Dismount and Save' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "WinPE Phase: Dismount and Save" -ForegroundColor Green if ($PromptBeforeDismount.IsPresent){[void](Read-Host 'Press Enter to Continue')} Dismount-WindowsImage -Path "$MountDirectory" -Save -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dismount-WindowsImage.log" | Out-Null #=================================================================================================== Write-Verbose '19.1.1 Export WinPE' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Export Boot.wim to $OS\sources\boot.wim" -ForegroundColor Green Export-WindowsImage -SourceImagePath "$WimTemp\boot.wim" -SourceIndex 1 -DestinationImagePath "$OS\sources\boot.wim" -Setbootable -DestinationName "$TaskName" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Export-WindowsImage.log" | Out-Null if ($PEOutput -eq 'MDT') { Export-WindowsImage -SourceImagePath "$WimTemp\boot.wim" -SourceIndex 1 -DestinationImagePath "$WorkingPath\LiteTouchPE_$OSArchitecture.wim" -Setbootable -DestinationName "$TaskName" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Export-WindowsImage.log" | Out-Null } if ($PEOutput -eq 'Recovery') { Export-WindowsImage -SourceImagePath "$WimTemp\boot.wim" -SourceIndex 1 -DestinationImagePath "$WorkingPath\WinRE.wim" -Setbootable -DestinationName "$TaskName" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Export-WindowsImage.log" | Out-Null } if ($PEOutput -eq 'WinPE') { Export-WindowsImage -SourceImagePath "$WimTemp\boot.wim" -SourceIndex 1 -DestinationImagePath "$WorkingPath\WinPE.wim" -Setbootable -DestinationName "$TaskName" -LogPath "$Info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Export-WindowsImage.log" | Out-Null } #=================================================================================================== Write-Verbose '19.1.1 Export Boot.wim Configuration' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Write-Host "Export Boot.wim Configuration to $WorkingPath\WindowsImage.txt" -ForegroundColor Green $GetWindowsImage = @() $GetWindowsImage = Get-WindowsImage -ImagePath "$OS\sources\boot.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 Get-WindowsImageContent' #=================================================================================================== Write-Host "$Info\Get-WindowsImageContent.txt" Get-WindowsImageContent -ImagePath "$OS\Sources\boot.wim" -Index 1 | Out-File "$Info\Get-WindowsImageContent.txt" #=================================================================================================== 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} #=================================================================================================== 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) { Write-Host '========================================================================================' -ForegroundColor DarkGray New-OSBMediaISO -FullName "$WorkingPath" } #=================================================================================================== Write-Verbose '19.1.1 Show-OSBMediaInfo' #=================================================================================================== if ($ShowMediaInfo.IsPresent) { Write-Host '========================================================================================' -ForegroundColor DarkGray Show-OSBMediaInfo -FullName $WorkingPath } #=================================================================================================== Write-Verbose '19.1.1 Stop Transcript' #=================================================================================================== Write-Host '========================================================================================' -ForegroundColor DarkGray Stop-Transcript } } } END { #Write-Host '========================================================================================' -ForegroundColor DarkGray #Write-Host "$($MyInvocation.MyCommand.Name) END" -ForegroundColor Green } } |