Included some better error handling if defining optionalfeatures that require source folders (netfx3). ESD files don't have source folders like ISO media, which means installing .net 3.5 as an optional feature would fail. Also cleaned up some formatting.
This commit is contained in:
rbalsleyMSFT
2023-06-02 13:55:49 -07:00
parent 5e7da0e0c5
commit b7b4a53b06
+29 -17
View File
@@ -121,6 +121,7 @@ param(
[ValidateScript({ [ValidateScript({
$allowedSKUs = @('Home', 'Home N', 'Home Single Language', 'Education', 'Education N', 'Pro', 'Pro N', 'Pro Education', 'Pro Education N', 'Pro for Workstations', 'Pro N for Workstations', 'Enterprise', 'Enterprise N') $allowedSKUs = @('Home', 'Home N', 'Home Single Language', 'Education', 'Education N', 'Pro', 'Pro N', 'Pro Education', 'Pro Education N', 'Pro for Workstations', 'Pro N for Workstations', 'Enterprise', 'Enterprise N')
if ($allowedSKUs -contains $_) { $true } else { throw "Invalid WindowsSKU value. Allowed values: $($allowedSKUs -join ', ')" } if ($allowedSKUs -contains $_) { $true } else { throw "Invalid WindowsSKU value. Allowed values: $($allowedSKUs -join ', ')" }
return $true
})] })]
[string]$WindowsSKU = 'Pro', [string]$WindowsSKU = 'Pro',
[ValidateScript({ Test-Path $_ })] [ValidateScript({ Test-Path $_ })]
@@ -145,12 +146,6 @@ param(
[String]$ShareName = "FFUCaptureShare", [String]$ShareName = "FFUCaptureShare",
[string]$Username = "ffu_user", [string]$Username = "ffu_user",
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[ValidateScript({
if (($InstallApps -and ($_ -eq $null)) -or (-not ($ISOPath) -and ($_ -eq $null))) {
throw "If variable InstallApps is set to `$true, VMHostIPAddress must also be set to capture the FFU"
}
return $true
})]
[string]$VMHostIPAddress, [string]$VMHostIPAddress,
[bool]$CreateCaptureMedia = $true, [bool]$CreateCaptureMedia = $true,
[bool]$CreateDeploymentMedia, [bool]$CreateDeploymentMedia,
@@ -181,7 +176,7 @@ param(
throw "Invalid optional feature '$feature'. Allowed values: $($allowedFeatures -join ', ')" throw "Invalid optional feature '$feature'. Allowed values: $($allowedFeatures -join ', ')"
} }
} }
$true return $true
})] })]
[string]$OptionalFeatures, [string]$OptionalFeatures,
[string]$ProductKey, [string]$ProductKey,
@@ -197,6 +192,7 @@ param(
'it-it', 'ja-jp', 'ko-kr', 'lt-lt', 'lv-lv', 'nb-no', 'nl-nl', 'pl-pl', 'pt-br', 'pt-pt', 'ro-ro', 'ru-ru', 'sk-sk', 'sl-si', 'sr-latn-rs', 'sv-se', 'th-th', 'tr-tr', 'uk-ua', 'it-it', 'ja-jp', 'ko-kr', 'lt-lt', 'lv-lv', 'nb-no', 'nl-nl', 'pl-pl', 'pt-br', 'pt-pt', 'ro-ro', 'ru-ru', 'sk-sk', 'sl-si', 'sr-latn-rs', 'sv-se', 'th-th', 'tr-tr', 'uk-ua',
'zh-cn', 'zh-tw') 'zh-cn', 'zh-tw')
if ($allowedLang -contains $_) { $true } else { throw "Invalid WindowsLang value. Allowed values: $($allowedLang -join ', ')" } if ($allowedLang -contains $_) { $true } else { throw "Invalid WindowsLang value. Allowed values: $($allowedLang -join ', ')" }
return $true
})] })]
[Parameter(Mandatory = $false)] [Parameter(Mandatory = $false)]
[string]$WindowsLang = 'en-us', [string]$WindowsLang = 'en-us',
@@ -206,11 +202,7 @@ param(
[ValidateSet(512, 4096)] [ValidateSet(512, 4096)]
[uint32]$LogicalSectorSizeBytes = 512 [uint32]$LogicalSectorSizeBytes = 512
) )
$version = '2306.1' $version = '2306.1.1'
if (($InstallOffice -eq $true) -and ($InstallApps -eq $false)) {
throw "If variable InstallOffice is set to `$true, InstallApps must also be set to `$true."
}
#Check if Hyper-V feature is installed (requires only checks the module) #Check if Hyper-V feature is installed (requires only checks the module)
$osInfo = Get-WmiObject -Class Win32_OperatingSystem $osInfo = Get-WmiObject -Class Win32_OperatingSystem
@@ -399,7 +391,8 @@ function Get-WindowsESD {
# Select cab file URL based on Windows Release # Select cab file URL based on Windows Release
$cabFileUrl = if ($WindowsRelease -eq 10) { $cabFileUrl = if ($WindowsRelease -eq 10) {
'https://go.microsoft.com/fwlink/?LinkId=841361' 'https://go.microsoft.com/fwlink/?LinkId=841361'
} else { }
else {
'https://go.microsoft.com/fwlink/?LinkId=2156292' 'https://go.microsoft.com/fwlink/?LinkId=2156292'
} }
@@ -1267,16 +1260,33 @@ Write-Host "FFU build process has begun. This process can take 20 minutes or mor
Write-Host "To track progress, please open the log file $Logfile or use the -Verbose parameter next time" Write-Host "To track progress, please open the log file $Logfile or use the -Verbose parameter next time"
WriteLog 'Begin Logging' WriteLog 'Begin Logging'
#Get script variable values
LogVariableValues
#Override $InstallApps value if using ESD to build FFU. This is due to a strange issue where building the FFU #Override $InstallApps value if using ESD to build FFU. This is due to a strange issue where building the FFU
#from vhdx doesn't work (you get an older style OOBE screen and get stuck in an OOBE reboot loop when hitting next). #from vhdx doesn't work (you get an older style OOBE screen and get stuck in an OOBE reboot loop when hitting next).
#This behavior doesn't happen with WIM files. #This behavior doesn't happen with WIM files.
If(-not ($ISOPath)){ If (-not ($ISOPath) -and (-not ($InstallApps))) {
$InstallApps = $true $InstallApps = $true
WriteLog "Script will download Windows media. Setting `$InstallApps to `$true to build VM to capture FFU. Must do this when using MCT ESD."
} }
if (($InstallOffice -eq $true) -and ($InstallApps -eq $false)) {
throw "If variable InstallOffice is set to `$true, InstallApps must also be set to `$true."
}
if (($InstallApps -and ($VMSwitchName -eq ''))) {
throw "If variable InstallApps is set to `$true, VMSwitchName must also be set to capture the FFU. Please set -VMSwitchName and try again."
}
if (($InstallApps -and ($VMHostIPAddress -eq ''))) {
throw "If variable InstallApps is set to `$true, VMHostIPAddress must also be set to capture the FFU. Please set -VMHostIPAddress and try again."
}
if (-not ($ISOPath) -and ($OptionalFeatures -like '*netfx3*')) {
throw "netfx3 specified as an optional feature, however Windows ISO isn't defined. Unable to get netfx3 source files from downloaded ESD media. Please specify a Windows ISO in the ISOPath parameter."
}
#Get script variable values
LogVariableValues
#Get Windows ADK #Get Windows ADK
try { try {
$adkPath = Get-ADK $adkPath = Get-ADK
@@ -1400,7 +1410,9 @@ catch {
} }
else { else {
#Remove ESD file #Remove ESD file
Remove-Item -Path $esdFilePath -Force WriteLog "Deleting ESD file"
Remove-Item -Path $wimPath -Force
WriteLog "ESD File deleted"
} }
throw $_ throw $_