Refactor CaptureFFU.ps1 to use $WindowsVersion and $WindowsRelease for improved clarity and consistency in FFU naming

This commit is contained in:
rbalsleyMSFT
2024-12-02 18:08:30 -08:00
parent a59210c559
commit db0fbfaaf4
@@ -13,7 +13,7 @@ reg load "HKLM\FFU" $Software
$SKU = Get-ItemPropertyValue -Path 'HKLM:\FFU\Microsoft\Windows NT\CurrentVersion\' -Name 'EditionID' $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' [int]$CurrentBuild = Get-ItemPropertyValue -Path 'HKLM:\FFU\Microsoft\Windows NT\CurrentVersion\' -Name 'CurrentBuild'
if ($CurrentBuild -notin 14393, 17763) { if ($CurrentBuild -notin 14393, 17763) {
$DisplayVersion = Get-ItemPropertyValue -Path 'HKLM:\FFU\Microsoft\Windows NT\CurrentVersion\' -Name 'DisplayVersion' $WindowsVersion = Get-ItemPropertyValue -Path 'HKLM:\FFU\Microsoft\Windows NT\CurrentVersion\' -Name 'DisplayVersion'
} }
$InstallationType = Get-ItemPropertyValue -Path 'HKLM:\FFU\Microsoft\Windows NT\CurrentVersion\' -Name 'InstallationType' $InstallationType = Get-ItemPropertyValue -Path 'HKLM:\FFU\Microsoft\Windows NT\CurrentVersion\' -Name 'InstallationType'
$BuildDate = Get-Date -uformat %b%Y $BuildDate = Get-Date -uformat %b%Y
@@ -38,60 +38,58 @@ $SKU = switch ($SKU) {
if ($InstallationType -eq "Client") { if ($InstallationType -eq "Client") {
if ($CurrentBuild -ge 22000) { if ($CurrentBuild -ge 22000) {
$Name = 'Win11' $WindowsRelease = 'Win11'
} }
else { else {
$Name = 'Win10' $WindowsRelease = 'Win10'
} }
} }
else { else {
$Name = switch ($CurrentBuild) { $WindowsRelease = switch ($CurrentBuild) {
26100 { '2025' } 26100 { '2025' }
20348 { '2022' } 20348 { '2022' }
17763 { '2019' } 17763 { '2019' }
14393 { '2016' } 14393 { '2016' }
Default { $DisplayVersion } Default { $WindowsVersion }
} }
if ($InstallationType -eq "Server Core") { if ($InstallationType -eq "Server Core") {
$SKU += "_Core" $SKU += "_Core"
} }
} }
#If Office is installed, modify the file name of the FFU if ($CustomFFUNameTemplate) {
#$Office = Get-childitem -Path 'M:\Program Files\Microsoft Office' -ErrorAction SilentlyContinue | Out-Null $CustomFFUNameTemplate = $CustomFFUNameTemplate -replace '{WindowsRelease}', $WindowsRelease
$Office = Get-childitem -Path 'M:\Program Files\Microsoft Office' -ErrorAction SilentlyContinue $CustomFFUNameTemplate = $CustomFFUNameTemplate -replace '{WindowsVersion}', $WindowsVersion
if ($Office) { $CustomFFUNameTemplate = $CustomFFUNameTemplate -replace '{SKU}', $SKU
$ffuFilePath = "W:\$Name`_$DisplayVersion`_$SKU`_Office`_$BuildDate.ffu" $CustomFFUNameTemplate = $CustomFFUNameTemplate -replace '{BuildDate}', $BuildDate
} else { $CustomFFUNameTemplate = $CustomFFUNameTemplate -replace '{yyyy}', (Get-Date -UFormat '%Y')
$ffuFilePath = "W:\$Name`_$DisplayVersion`_$SKU`_Apps`_$BuildDate.ffu" $CustomFFUNameTemplate = $CustomFFUNameTemplate -creplace '{MM}', (Get-Date -UFormat '%m')
} $CustomFFUNameTemplate = $CustomFFUNameTemplate -replace '{dd}', (Get-Date -UFormat '%d')
$dismArgs = "/capture-ffu /imagefile=$ffuFilePath /capturedrive=\\.\PhysicalDrive0 /name:$Name$DisplayVersion$SKU /Compress:Default" $CustomFFUNameTemplate = $CustomFFUNameTemplate -creplace '{HH}', (Get-Date -UFormat '%H')
$CustomFFUNameTemplate = $CustomFFUNameTemplate -creplace '{hh}', (Get-Date -UFormat '%I')
if (![string]::IsNullOrEmpty($CustomFFUNameTemplate)) { $CustomFFUNameTemplate = $CustomFFUNameTemplate -creplace '{mm}', (Get-Date -UFormat '%M')
$CustomFFUNameTemplate = $CustomFFUNameTemplate -replace "{Name}", $Name $CustomFFUNameTemplate = $CustomFFUNameTemplate -replace '{tt}', (Get-Date -UFormat '%p')
$CustomFFUNameTemplate = $CustomFFUNameTemplate -replace "{DisplayVersion}", $DisplayVersion if($CustomFFUNameTemplate -notlike '*.ffu') {
$CustomFFUNameTemplate = $CustomFFUNameTemplate -replace "{SKU}", $SKU $CustomFFUNameTemplate += '.ffu'
$CustomFFUNameTemplate = $CustomFFUNameTemplate -replace "{BuildDate}", $BuildDate
$CustomFFUNameTemplate = $CustomFFUNameTemplate -replace "{yyyy}", (Get-Date -UFormat "%Y")
$CustomFFUNameTemplate = $CustomFFUNameTemplate -replace "{MM}", (Get-Date -UFormat "%m")
$CustomFFUNameTemplate = $CustomFFUNameTemplate -replace "{dd}", (Get-Date -UFormat "%d")
$CustomFFUNameTemplate = $CustomFFUNameTemplate -replace "{HH}", (Get-Date -UFormat "%H")
$CustomFFUNameTemplate = $CustomFFUNameTemplate -replace "{hh}", (Get-Date -UFormat "%I")
$CustomFFUNameTemplate = $CustomFFUNameTemplate -replace "{mm}", (Get-Date -UFormat "%M")
$CustomFFUNameTemplate = $CustomFFUNameTemplate -replace "{tt}", (Get-Date -UFormat "%p")
if (!$CustomFFUNameTemplate.EndsWith(".ffu")) {
$CustomFFUNameTemplate += ".ffu"
} }
$dismArgs = "/capture-ffu /imagefile=W:\$CustomFFUNameTemplate /capturedrive=\\.\PhysicalDrive0 /name:$WindowsRelease$WindowsVersion$SKU /Compress:Default"
$dismArgs = "/capture-ffu /imagefile=W:\$CustomFFUNameTemplate /capturedrive=\\.\PhysicalDrive0 /name:$Name$DisplayVersion$SKU /Compress:Default" } else {
#If Office is installed, modify the file name of the FFU
#$Office = Get-childitem -Path 'M:\Program Files\Microsoft Office' -ErrorAction SilentlyContinue | Out-Null
$Office = Get-ChildItem -Path 'M:\Program Files\Microsoft Office' -ErrorAction SilentlyContinue
if ($Office) {
$ffuFilePath = "W:\$WindowsRelease`_$WindowsVersion`_$SKU`_Office`_$BuildDate.ffu"
} else {
$ffuFilePath = "W:\$WindowsRelease`_$WindowsVersion`_$SKU`_Apps`_$BuildDate.ffu"
}
$dismArgs = "/capture-ffu /imagefile=$ffuFilePath /capturedrive=\\.\PhysicalDrive0 /name:$WindowsRelease$WindowsVersion$SKU /Compress:Default"
} }
#Unload Registry #Unload Registry
Set-Location X:\ Set-Location X:\
Remove-Variable SKU Remove-Variable SKU
if ($CurrentBuild -notin 14393, 17763) { if ($CurrentBuild -notin 14393, 17763) {
Remove-Variable DisplayVersion Remove-Variable WindowsVersion
} }
Remove-Variable CurrentBuild Remove-Variable CurrentBuild
Remove-Variable Office Remove-Variable Office
@@ -102,5 +100,4 @@ Start-sleep 60
Start-Process -FilePath dism.exe -ArgumentList $dismArgs -Wait -PassThru -ErrorAction Stop | Out-Null Start-Process -FilePath dism.exe -ArgumentList $dismArgs -Wait -PassThru -ErrorAction Stop | Out-Null
#Copy DISM log to Host #Copy DISM log to Host
xcopy X:\Windows\logs\dism\dism.log W:\ /Y | Out-Null xcopy X:\Windows\logs\dism\dism.log W:\ /Y | Out-Null
wpeutil Shutdown wpeutil Shutdown