Private/OSB-WinPE.ps1
function Export-OSBWinPEWims { [CmdletBinding()] PARAM ( [string]$MountDirectory, [string]$OSMediaPath ) Write-Host "WinPE: Export WIMs to $OSMediaPath\WinPE" -ForegroundColor Green Write-Verbose 'Export-OSBWinPEWims' Write-Verbose "MountDirectory: $MountDirectory" Write-Verbose "OSMediaPath: $OSMediaPath" Write-Verbose "$OSMediaPath\WinPE\boot.wim" Copy-Item -Path "$OSMediaPath\OS\sources\boot.wim" -Destination "$OSMediaPath\WinPE\boot.wim" -Force Write-Verbose "$OSMediaPath\WinPE\winpe.wim" $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Export-WindowsImage-winpe.wim.log" Write-Verbose "$CurrentLog" Export-WindowsImage -SourceImagePath "$OSMediaPath\OS\sources\boot.wim" -SourceIndex 1 -DestinationImagePath "$OSMediaPath\WinPE\winpe.wim" -LogPath "$CurrentLog" | Out-Null Write-Verbose "$OSMediaPath\WinPE\setup.wim" $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Export-WindowsImage-setup.wim.log" Write-Verbose "$CurrentLog" Export-WindowsImage -SourceImagePath "$OSMediaPath\OS\sources\boot.wim" -SourceIndex 2 -DestinationImagePath "$OSMediaPath\WinPE\setup.wim" -LogPath "$CurrentLog" | Out-Null Write-Verbose "$OSMediaPath\WinPE\winre.wim" $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Export-WindowsImage-winre.wim.log" Write-Verbose "$CurrentLog" Export-WindowsImage -SourceImagePath "$MountDirectory\Windows\System32\Recovery\winre.wim" -SourceIndex 1 -DestinationImagePath "$OSMediaPath\WinPE\winre.wim" -LogPath "$CurrentLog" | Out-Null } function Mount-OSBWinPE { [CmdletBinding()] PARAM ( [string]$OSMediaPath, [string]$MountSetup, [string]$MountWinPE, [string]$MountWinRE ) Write-Host "WinPE: Mount WIMs" -ForegroundColor Green Write-Verbose '========== Mount-OSBWinPE' Write-Verbose "OSMediaPath: $OSMediaPath" Write-Verbose "MountSetup: $MountSetup" Write-Verbose "MountWinPE: $MountWinPE" Write-Verbose "MountWinRE: $MountWinRE" Write-Verbose "$MountSetup" $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Mount-WindowsImage-setup.wim.log" Write-Verbose "$CurrentLog" Mount-WindowsImage -ImagePath "$OSMediaPath\WimTemp\setup.wim" -Index 1 -Path "$MountSetup" -LogPath "$CurrentLog" | Out-Null Write-Verbose "$MountWinPE" $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Mount-WindowsImage-winpe.wim.log" Write-Verbose "$CurrentLog" Mount-WindowsImage -ImagePath "$OSMediaPath\WimTemp\winpe.wim" -Index 1 -Path "$MountWinPE" -LogPath "$CurrentLog" | Out-Null Write-Verbose "$MountWinRE" $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Mount-WindowsImage-winre.wim.log" Write-Verbose "$CurrentLog" Mount-WindowsImage -ImagePath "$OSMediaPath\WimTemp\winre.wim" -Index 1 -Path "$MountWinRE" -LogPath "$CurrentLog" | Out-Null } function Update-OSBWinPESources { [CmdletBinding()] PARAM ( [string]$OSMediaPath, [string]$MountSetup ) Write-Host "Media: Update Sources with Setup.wim" -ForegroundColor Green Write-Verbose '========== Update-OSBWinPESources' Write-Verbose "OSMediaPath: $OSMediaPath" Write-Verbose "MountSetup: $MountSetup" robocopy "$MountSetup\sources" "$OSMediaPath\OS\sources" setup.exe /ndl /xo /xx /xl /b /np /ts /tee /r:0 /w:0 /Log+:"$OSMediaPath\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Robocopy-setup.wim-MediaSources.log" | Out-Null robocopy "$MountSetup\sources" "$OSMediaPath\OS\sources" setuphost.exe /ndl /xo /xx /xl /b /np /ts /tee /r:0 /w:0 /Log+:"$OSMediaPath\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Robocopy-setup.wim-MediaSources.log" | Out-Null } function Export-OSBWinPEPackages { [CmdletBinding()] PARAM ( [string]$OSMediaPath, [string]$MountSetup, [string]$MountWinPE, [string]$MountWinRE ) Write-Host "WinPE: Export Package Inventory to $OSMediaPath\WinPE\info" -ForegroundColor Green Write-Verbose '========== Export-OSBWinPEPackages' Write-Verbose "OSMediaPath: $OSMediaPath" Write-Verbose "MountSetup: $MountSetup" Write-Verbose "MountWinPE: $MountWinPE" Write-Verbose "MountWinRE: $MountWinRE" #=================================================================================================== Write-Verbose 'Get-WindowsPackage Setup' #=================================================================================================== $GetWindowsPackage = @() Write-Verbose "$OSMediaPath\WinPE\info\setup-WindowsPackage.txt" $GetWindowsPackage = Get-WindowsPackage -Path "$MountSetup" $GetWindowsPackage | Out-File "$OSMediaPath\WinPE\info\setup-WindowsPackage.txt" $GetWindowsPackage | Out-File "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsPackage-setup.wim.txt" $GetWindowsPackage | Export-Clixml -Path "$OSMediaPath\WinPE\info\xml\Get-WindowsPackage-setup.wim.xml" $GetWindowsPackage | Export-Clixml -Path "$OSMediaPath\WinPE\info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsPackage-setup.wim.xml" $GetWindowsPackage | ConvertTo-Json | Out-File "$OSMediaPath\WinPE\info\json\Get-WindowsPackage-setup.wim.json" $GetWindowsPackage | ConvertTo-Json | Out-File "$OSMediaPath\WinPE\info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsPackage-setup.wim.json" #=================================================================================================== Write-Verbose 'Get-WindowsPackage WinPE' #=================================================================================================== $GetWindowsPackage = @() Write-Verbose "$OSMediaPath\WinPE\info\winpe-WindowsPackage.txt" $GetWindowsPackage = Get-WindowsPackage -Path "$MountWinPE" $GetWindowsPackage | Out-File "$OSMediaPath\WinPE\info\winpe-WindowsPackage.txt" $GetWindowsPackage | Out-File "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsPackage-winpe.wim.txt" $GetWindowsPackage | Export-Clixml -Path "$OSMediaPath\WinPE\info\xml\Get-WindowsPackage-winpe.wim.xml" $GetWindowsPackage | Export-Clixml -Path "$OSMediaPath\WinPE\info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsPackage-winpe.wim.xml" $GetWindowsPackage | ConvertTo-Json | Out-File "$OSMediaPath\WinPE\info\json\Get-WindowsPackage-winpe.wim.json" $GetWindowsPackage | ConvertTo-Json | Out-File "$OSMediaPath\WinPE\info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsPackage-winpe.wim.json" #=================================================================================================== Write-Verbose 'Get-WindowsPackage WinRE' #=================================================================================================== $GetWindowsPackage = @() Write-Verbose "$OSMediaPath\WinPE\info\winre-WindowsPackage.txt" $GetWindowsPackage = Get-WindowsPackage -Path "$MountWinRE" $GetWindowsPackage | Out-File "$OSMediaPath\WinPE\info\winre-WindowsPackage.txt" $GetWindowsPackage | Out-File "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsPackage-winre.wim.txt" $GetWindowsPackage | Export-Clixml -Path "$OSMediaPath\WinPE\info\xml\Get-WindowsPackage-winre.wim.xml" $GetWindowsPackage | Export-Clixml -Path "$OSMediaPath\WinPE\info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsPackage-winre.wim.xml" $GetWindowsPackage | ConvertTo-Json | Out-File "$OSMediaPath\WinPE\info\json\Get-WindowsPackage-winre.wim.json" $GetWindowsPackage | ConvertTo-Json | Out-File "$OSMediaPath\WinPE\info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsPackage-winre.wim.json" } function Dismount-OSBWinPE { [CmdletBinding()] PARAM ( [string]$OSMediaPath, [string]$MountSetup, [string]$MountWinPE, [string]$MountWinRE ) Write-Host "WinPE: Dismount and Save" -ForegroundColor Green Write-Verbose '========== Dismount-OSBWinPE' Write-Verbose "OSMediaPath: $OSMediaPath" Write-Verbose "MountSetup: $MountSetup" Write-Verbose "MountWinPE: $MountWinPE" Write-Verbose "MountWinRE: $MountWinRE" Write-Verbose "$MountSetup" $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dismount-WindowsImage-setup.wim.log" Write-Verbose "$CurrentLog" Dismount-WindowsImage -Path "$MountSetup" -Save -LogPath "$CurrentLog" | Out-Null Write-Verbose "$MountWinPE" $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dismount-WindowsImage-winpe.wim.log" Write-Verbose "$CurrentLog" Dismount-WindowsImage -Path "$MountWinPE" -Save -LogPath "$CurrentLog" | Out-Null Write-Verbose "$MountWinRE" $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Dismount-WindowsImage-winre.wim.log" Write-Verbose "$CurrentLog" Dismount-WindowsImage -Path "$MountWinRE" -Save -LogPath "$CurrentLog" | Out-Null } function Export-OSBWinPE { [CmdletBinding()] PARAM ( [string]$OSMediaPath, [string]$MountSetup, [string]$MountWinPE, [string]$MountWinRE ) Write-Host "WinPE: Export WIMs to $OSMediaPath\WinPE" -ForegroundColor Green Write-Verbose '========== Export-OSBWinPE' Write-Verbose "OSMediaPath: $OSMediaPath" Write-Verbose "MountSetup: $MountSetup" Write-Verbose "MountWinPE: $MountWinPE" Write-Verbose "MountWinRE: $MountWinRE" $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Export-WindowsImage-setup.wim.log" Write-Verbose "$CurrentLog" Export-WindowsImage -SourceImagePath "$OSMediaPath\WimTemp\setup.wim" -SourceIndex 1 -DestinationImagePath "$OSMediaPath\WinPE\setup.wim" -LogPath "$CurrentLog" | Out-Null $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Export-WindowsImage-winpe.wim.log" Write-Verbose "$CurrentLog" Export-WindowsImage -SourceImagePath "$OSMediaPath\WimTemp\winpe.wim" -SourceIndex 1 -DestinationImagePath "$OSMediaPath\WinPE\winpe.wim" -LogPath "$CurrentLog" | Out-Null $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Export-WindowsImage-winre.wim.log" Write-Verbose "$CurrentLog" Export-WindowsImage -SourceImagePath "$OSMediaPath\WimTemp\winre.wim" -SourceIndex 1 -DestinationImagePath "$OSMediaPath\WinPE\winre.wim" -LogPath "$CurrentLog" | Out-Null } function Export-OSBWinPEBootWim { [CmdletBinding()] PARAM ( [string]$OSMediaPath ) Write-Host "WinPE: Rebuild $OSMediaPath\OS\sources\boot.wim" -ForegroundColor Green Write-Verbose '========== Export-OSBWinPEBootWim' Write-Verbose "OSMediaPath: $OSMediaPath" $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Export-WindowsImage-winpe.wim.log" Write-Verbose "$CurrentLog" Export-WindowsImage -SourceImagePath "$OSMediaPath\WimTemp\winpe.wim" -SourceIndex 1 -DestinationImagePath "$OSMediaPath\WinPE\boot.wim" -LogPath "$CurrentLog" | Out-Null $CurrentLog = "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Export-WindowsImage-setup.wim.log" Write-Verbose "$CurrentLog" Export-WindowsImage -SourceImagePath "$OSMediaPath\WimTemp\setup.wim" -SourceIndex 1 -DestinationImagePath "$OSMediaPath\WinPE\boot.wim" -Setbootable -LogPath "$CurrentLog" | Out-Null Copy-Item -Path "$OSMediaPath\WinPE\boot.wim" -Destination "$OSMediaPath\OS\sources\boot.wim" -Force | Out-Null } function Export-OSBWinPEInventory { [CmdletBinding()] PARAM ( [string]$OSMediaPath ) Write-Host "WinPE: Export WIM Inventory to $OSMediaPath\WinPE\info" -ForegroundColor Green Write-Verbose 'Export-OSBWinPEInventory' Write-Verbose "OSMediaPath: $OSMediaPath" #=================================================================================================== Write-Verbose 'Get-WindowsImage Boot.wim' #=================================================================================================== $GetWindowsImage = @() Write-Verbose "$OSMediaPath\WinPE\info\boot.txt" $GetWindowsImage = Get-WindowsImage -ImagePath "$OSMediaPath\WinPE\boot.wim" $GetWindowsImage | Out-File "$OSMediaPath\WinPE\info\boot.txt" (Get-Content "$OSMediaPath\WinPE\info\boot.txt") | Where-Object {$_.Trim(" `t")} | Set-Content "$OSMediaPath\WinPE\info\boot.txt" $GetWindowsImage | Out-File "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-boot.wim.txt" $GetWindowsImage | Export-Clixml -Path "$OSMediaPath\WinPE\info\xml\Get-WindowsImage-boot.wim.xml" $GetWindowsImage | Export-Clixml -Path "$OSMediaPath\WinPE\info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-boot.wim.xml" $GetWindowsImage | ConvertTo-Json | Out-File "$OSMediaPath\WinPE\info\json\Get-WindowsImage-boot.wim.json" $GetWindowsImage | ConvertTo-Json | Out-File "$OSMediaPath\WinPE\info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-boot.wim.json" #=================================================================================================== Write-Verbose 'Get-WindowsImage WinPE' #=================================================================================================== $GetWindowsImage = @() Write-Verbose "$OSMediaPath\WinPE\info\winpe.txt" $GetWindowsImage = Get-WindowsImage -ImagePath "$OSMediaPath\WinPE\winpe.wim" -Index 1 | Select-Object -Property * $GetWindowsImage | Out-File "$OSMediaPath\WinPE\info\winpe.txt" (Get-Content "$OSMediaPath\WinPE\info\winpe.txt") | Where-Object {$_.Trim(" `t")} | Set-Content "$OSMediaPath\WinPE\info\winpe.txt" $GetWindowsImage | Out-File "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-winpe.wim.txt" $GetWindowsImage | Export-Clixml -Path "$OSMediaPath\WinPE\info\xml\Get-WindowsImage-winpe.wim.xml" $GetWindowsImage | Export-Clixml -Path "$OSMediaPath\WinPE\info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-winpe.wim.xml" $GetWindowsImage | ConvertTo-Json | Out-File "$OSMediaPath\WinPE\info\json\Get-WindowsImage-winpe.wim.json" $GetWindowsImage | ConvertTo-Json | Out-File "$OSMediaPath\WinPE\info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-winpe.wim.json" #=================================================================================================== Write-Verbose 'Get-WindowsImage WinRE' #=================================================================================================== $GetWindowsImage = @() Write-Verbose "$OSMediaPath\WinPE\info\winre.txt" $GetWindowsImage = Get-WindowsImage -ImagePath "$OSMediaPath\WinPE\winre.wim" -Index 1 | Select-Object -Property * $GetWindowsImage | Out-File "$OSMediaPath\WinPE\info\winre.txt" (Get-Content "$OSMediaPath\WinPE\info\winre.txt") | Where-Object {$_.Trim(" `t")} | Set-Content "$OSMediaPath\WinPE\info\winre.txt" $GetWindowsImage | Out-File "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-winre.wim.txt" $GetWindowsImage | Export-Clixml -Path "$OSMediaPath\WinPE\info\xml\Get-WindowsImage-winre.wim.xml" $GetWindowsImage | Export-Clixml -Path "$OSMediaPath\WinPE\info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-winre.wim.xml" $GetWindowsImage | ConvertTo-Json | Out-File "$OSMediaPath\WinPE\info\json\Get-WindowsImage-winre.wim.json" $GetWindowsImage | ConvertTo-Json | Out-File "$OSMediaPath\WinPE\info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-winre.wim.json" #=================================================================================================== Write-Verbose 'Get-WindowsImage Setup' #=================================================================================================== $GetWindowsImage = @() Write-Verbose "$OSMediaPath\WinPE\info\setup.txt" $GetWindowsImage = Get-WindowsImage -ImagePath "$OSMediaPath\WinPE\setup.wim" -Index 1 | Select-Object -Property * $GetWindowsImage | Out-File "$OSMediaPath\WinPE\info\setup.txt" (Get-Content "$OSMediaPath\WinPE\info\setup.txt") | Where-Object {$_.Trim(" `t")} | Set-Content "$OSMediaPath\WinPE\info\setup.txt" $GetWindowsImage | Out-File "$OSMediaPath\WinPE\info\logs\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-setup.wim.txt" $GetWindowsImage | Export-Clixml -Path "$OSMediaPath\WinPE\info\xml\Get-WindowsImage-setup.wim.xml" $GetWindowsImage | Export-Clixml -Path "$OSMediaPath\WinPE\info\xml\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-setup.wim.xml" $GetWindowsImage | ConvertTo-Json | Out-File "$OSMediaPath\WinPE\info\json\Get-WindowsImage-setup.wim.json" $GetWindowsImage | ConvertTo-Json | Out-File "$OSMediaPath\WinPE\info\json\$((Get-Date).ToString('yyyy-MM-dd-HHmmss'))-Get-WindowsImage-setup.wim.json" } |