From d7e4a32183f7e004a7227ac4b59e8b1095a831fe Mon Sep 17 00:00:00 2001 From: rbalsleyMSFT <53497092+rbalsleyMSFT@users.noreply.github.com> Date: Wed, 15 Feb 2023 16:49:53 -0800 Subject: [PATCH] Add files via upload --- WinPECaptureFFUFiles/AssignDriveLetter.txt | 4 ++ WinPECaptureFFUFiles/CaptureFFU.ps1 | 58 +++++++++++++++++++ .../Windows/System32/startnet.cmd | 5 ++ 3 files changed, 67 insertions(+) create mode 100644 WinPECaptureFFUFiles/AssignDriveLetter.txt create mode 100644 WinPECaptureFFUFiles/CaptureFFU.ps1 create mode 100644 WinPECaptureFFUFiles/Windows/System32/startnet.cmd diff --git a/WinPECaptureFFUFiles/AssignDriveLetter.txt b/WinPECaptureFFUFiles/AssignDriveLetter.txt new file mode 100644 index 0000000..fe8628f --- /dev/null +++ b/WinPECaptureFFUFiles/AssignDriveLetter.txt @@ -0,0 +1,4 @@ +select disk 0 +select partition 3 +Assign letter="M" +exit diff --git a/WinPECaptureFFUFiles/CaptureFFU.ps1 b/WinPECaptureFFUFiles/CaptureFFU.ps1 new file mode 100644 index 0000000..ea19629 --- /dev/null +++ b/WinPECaptureFFUFiles/CaptureFFU.ps1 @@ -0,0 +1,58 @@ +#Modify the net use path to map the W: drive to the location you want to copy the FFU file to +net use W: \\192.168.1.2\c$\temp /user:administrator p@ssw0rd + +$AssignDriveLetter = 'x:\AssignDriveLetter.txt' +Start-Process -FilePath diskpart.exe -ArgumentList "/S $AssignDriveLetter" -Wait -ErrorAction Stop | Out-Null +#Load Registry Hive +$Software = 'M:\Windows\System32\config\software' +reg load "HKLM\FFU" $Software + +#Find Windows version values + +$SKU = Get-ItemPropertyValue -Path 'HKLM:\FFU\Microsoft\Windows NT\CurrentVersion\' -Name 'EditionID' +[int]$CurrentBuild = Get-ItemPropertyValue -Path 'HKLM:\FFU\Microsoft\Windows NT\CurrentVersion\' -Name 'CurrentBuild' +$DisplayVersion = Get-ItemPropertyValue -Path 'HKLM:\FFU\Microsoft\Windows NT\CurrentVersion\' -Name 'DisplayVersion' +$BuildDate = Get-Date -uformat %b%Y + +$SKU = switch ($SKU){ + Home {'Home'} + Professional {'Pro'} + ProfessionalEducation {'Pro_Edu'} + Enterprise {'Ent'} +} + +if($CurrentBuild -ge 22000){ + $Name = 'Win11' +} +else{ + $Name = 'Win10' +} + +#If Office is installed, modify the file name of the FFU +$Office = Get-childitem -Path 'M:\Program Files\Microsoft Office' -ErrorAction SilentlyContinue | Out-Null +if($Office){ + $ffuFilePath = "W:\$Name`_$DisplayVersion`_$SKU`_Office`_$BuildDate.ffu" + $dismArgs = "/capture-ffu /imagefile=$ffuFilePath /capturedrive=\\.\PhysicalDrive0 /name:$Name$DisplayVersion$SKU /Compress:Default" + + +} +else{ + $ffuFilePath = "W:\$Name`_$DisplayVersion`_$SKU`_$BuildDate.ffu" + $dismArgs = "/capture-ffu /imagefile=$ffuFilePath /capturedrive=\\.\PhysicalDrive0 /name:$Name$DisplayVersion$SKU /Compress:Default" + +} + +#Unload Registry +Set-Location X:\ +Remove-Variable SKU +Remove-Variable CurrentBuild +Remove-Variable DisplayVersion +Remove-Variable Office +reg unload "HKLM\FFU" + +Start-Process -FilePath dism.exe -ArgumentList $dismArgs -Wait -PassThru -ErrorAction Stop | Out-Null +$dismOptArgs = "/optimize-ffu /imagefile:$ffuFilePath" +Start-Process -FilePath dism.exe -ArgumentList $dismOptArgs -Wait -PassThru -ErrorAction Stop | Out-Null +#Copy DISM log to Host +xcopy X:\Windows\logs\dism\dism.log W:\ /Y | Out-Null +shutdown /p diff --git a/WinPECaptureFFUFiles/Windows/System32/startnet.cmd b/WinPECaptureFFUFiles/Windows/System32/startnet.cmd new file mode 100644 index 0000000..0faedbc --- /dev/null +++ b/WinPECaptureFFUFiles/Windows/System32/startnet.cmd @@ -0,0 +1,5 @@ +wpeinit +powercfg /s 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c +powershell -Noprofile -ExecutionPolicy Bypass -File x:\CaptureFFU.ps1 +exit +