diff --git a/FFUDevelopment/BuildFFUVM.ps1 b/FFUDevelopment/BuildFFUVM.ps1 index bb61540..ba73768 100644 --- a/FFUDevelopment/BuildFFUVM.ps1 +++ b/FFUDevelopment/BuildFFUVM.ps1 @@ -73,7 +73,7 @@ When set to $true, will copy the provisioning package from the $FFUDevelopmentPa When set to $true, will copy the $FFUDevelopmentPath\Unattend folder to the Deployment partition of the USB drive. Default is $false. .PARAMETER DeviceNamingMode -Controls how device naming is handled when unattend content is copied to USB media or injected into the FFU. Supported values are Legacy, None, Template, and Prefixes. +Controls how device naming is handled when unattend content is copied to USB media or injected into the FFU. Supported values are Legacy, None, Prompt, Template, and Prefixes. .PARAMETER DeviceNameTemplate Sets the device name used when DeviceNamingMode is Template. Supports a static name or the %serial% token when CopyUnattend is used. @@ -419,7 +419,7 @@ param( [bool]$AllowVHDXCaching, [bool]$CopyPPKG, [bool]$CopyUnattend, - [ValidateSet('Legacy', 'None', 'Template', 'Prefixes')] + [ValidateSet('Legacy', 'None', 'Prompt', 'Template', 'Prefixes')] [string]$DeviceNamingMode = 'Legacy', [string]$DeviceNameTemplate, [string[]]$DeviceNamePrefixes, @@ -557,7 +557,7 @@ function Save-StagedUnattendFile { [Parameter(Mandatory = $true)] [string]$DestinationPath, [Parameter(Mandatory = $true)] - [ValidateSet('Legacy', 'None', 'Template', 'Prefixes')] + [ValidateSet('Legacy', 'None', 'Prompt', 'Template', 'Prefixes')] [string]$DeviceNamingMode, [string]$DeviceNameTemplate ) @@ -588,6 +588,9 @@ function Save-StagedUnattendFile { if ($DeviceNamingMode -eq 'None') { $computerNameComponent.ComputerName = '*' } + elseif ($DeviceNamingMode -eq 'Prompt') { + $computerNameComponent.ComputerName = 'MyComputer' + } elseif ($DeviceNamingMode -eq 'Template') { $computerNameComponent.ComputerName = $DeviceNameTemplate } @@ -638,6 +641,11 @@ if ($DeviceNamingMode -eq 'Template') { throw 'The %serial% device name variable is only supported when CopyUnattend is used.' } } +elseif ($DeviceNamingMode -eq 'Prompt') { + if (-not $CopyUnattend) { + throw 'DeviceNamingMode Prompt requires CopyUnattend. Prompt-based naming is not supported with InjectUnattend.' + } +} elseif ($DeviceNamingMode -eq 'Prefixes') { if (-not $CopyUnattend) { throw 'DeviceNamingMode Prefixes requires CopyUnattend. Prefix-based naming is not supported with InjectUnattend.' @@ -4364,6 +4372,9 @@ Function New-DeploymentUSB { if ($DeviceNamingMode -eq 'None') { $computerNameComponent.ComputerName = '*' } + elseif ($DeviceNamingMode -eq 'Prompt') { + $computerNameComponent.ComputerName = 'MyComputer' + } elseif ($DeviceNamingMode -eq 'Template') { $computerNameComponent.ComputerName = $DeviceNameTemplate } @@ -5706,10 +5717,10 @@ if ($CopyUnattend) { throw "-CopyUnattend is set to `$true, but the $UnattendFolder folder is missing a .XML file" } - if ($DeviceNamingMode -eq 'Prefixes') { + if ($DeviceNamingMode -in @('Prompt', 'Prefixes')) { $unattendSourcePath = Get-UnattendSourcePath -UnattendFolder $UnattendFolder -WindowsArch $WindowsArch if (-not (Test-UnattendHasComputerNameElement -Path $unattendSourcePath)) { - throw "DeviceNamingMode Prefixes requires a ComputerName element in $unattendSourcePath" + throw "DeviceNamingMode $DeviceNamingMode requires a ComputerName element in $unattendSourcePath" } } diff --git a/FFUDevelopment/BuildFFUVM_UI.ps1 b/FFUDevelopment/BuildFFUVM_UI.ps1 index 90b8e32..b0771cc 100644 --- a/FFUDevelopment/BuildFFUVM_UI.ps1 +++ b/FFUDevelopment/BuildFFUVM_UI.ps1 @@ -439,7 +439,15 @@ $script:uiState.Controls.btnRun.Add_Click({ return } - if ($config.DeviceNamingMode -eq 'Template') { + if ($config.DeviceNamingMode -eq 'Prompt') { + if (-not $config.CopyUnattend) { + [System.Windows.MessageBox]::Show("Select Copy Unattend.xml before using 'Prompt for Device Name'.", "Copy Unattend Required", "OK", "Warning") | Out-Null + $btnRun.IsEnabled = $true + $script:uiState.Controls.txtStatus.Text = "Build canceled: prompt naming requires Copy Unattend.xml." + return + } + } + elseif ($config.DeviceNamingMode -eq 'Template') { if ([string]::IsNullOrWhiteSpace([string]$config.DeviceNameTemplate)) { [System.Windows.MessageBox]::Show("Specify a device name before using 'Specify Device Name'.", "Device Name Required", "OK", "Warning") | Out-Null $btnRun.IsEnabled = $true diff --git a/FFUDevelopment/BuildFFUVM_UI.xaml b/FFUDevelopment/BuildFFUVM_UI.xaml index 7ed2603..038e261 100644 --- a/FFUDevelopment/BuildFFUVM_UI.xaml +++ b/FFUDevelopment/BuildFFUVM_UI.xaml @@ -910,6 +910,7 @@ + diff --git a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Config.psm1 b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Config.psm1 index 1d92654..f31c69f 100644 --- a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Config.psm1 +++ b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Config.psm1 @@ -472,7 +472,10 @@ function Update-UIFromConfig { if ($ConfigContent.PSObject.Properties.Name -contains 'DeviceNamingMode') { $deviceNamingMode = [string]$ConfigContent.DeviceNamingMode } - if ($deviceNamingMode -notin @('None', 'Template', 'Prefixes')) { + if ($deviceNamingMode -eq 'Legacy') { + $deviceNamingMode = 'Prompt' + } + if ($deviceNamingMode -notin @('None', 'Prompt', 'Template', 'Prefixes')) { $deviceNamingMode = 'None' } Set-DeviceNamingMode -State $State -Mode $deviceNamingMode diff --git a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 index 5fa99e3..0fe70fc 100644 --- a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 +++ b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Handlers.psm1 @@ -30,6 +30,10 @@ function Update-VMNetworkingControls { function Get-SelectedDeviceNamingMode { param([PSCustomObject]$State) + if ($true -eq $State.Controls.rbDeviceNamingPrompt.IsChecked) { + return 'Prompt' + } + if ($true -eq $State.Controls.rbDeviceNamingTemplate.IsChecked) { return 'Template' } @@ -44,11 +48,12 @@ function Get-SelectedDeviceNamingMode { function Set-DeviceNamingMode { param( [PSCustomObject]$State, - [ValidateSet('None', 'Template', 'Prefixes')] + [ValidateSet('None', 'Prompt', 'Template', 'Prefixes')] [string]$Mode ) $State.Controls.rbDeviceNamingNone.IsChecked = $Mode -eq 'None' + $State.Controls.rbDeviceNamingPrompt.IsChecked = $Mode -eq 'Prompt' $State.Controls.rbDeviceNamingTemplate.IsChecked = $Mode -eq 'Template' $State.Controls.rbDeviceNamingPrefixes.IsChecked = $Mode -eq 'Prefixes' } @@ -132,9 +137,10 @@ function Update-UnattendSelectionControls { $isCopyUnattendSelected = $true -eq $State.Controls.chkCopyUnattend.IsChecked $isInjectUnattendSelected = $true -eq $State.Controls.chkInjectUnattend.IsChecked $deviceNameTemplateUsesSerialToken = Test-DeviceNameTemplateUsesSerialToken -State $State + $requiresCopiedUnattend = ($selectedDeviceNamingMode -in @('Prompt', 'Prefixes')) -or $deviceNameTemplateUsesSerialToken if ($isCopyUnattendSelected -and $isInjectUnattendSelected) { - if (($selectedDeviceNamingMode -eq 'Prefixes') -or $deviceNameTemplateUsesSerialToken) { + if ($requiresCopiedUnattend) { $State.Controls.chkInjectUnattend.IsChecked = $false $isInjectUnattendSelected = $false } @@ -144,7 +150,7 @@ function Update-UnattendSelectionControls { } } - if (($selectedDeviceNamingMode -eq 'Prefixes') -or $deviceNameTemplateUsesSerialToken) { + if ($requiresCopiedUnattend) { if (-not $isCopyUnattendSelected) { $State.Controls.chkCopyUnattend.IsChecked = $true $isCopyUnattendSelected = $true @@ -177,13 +183,14 @@ function Update-UnattendSelectionControls { function Update-DeviceNamingControls { param([PSCustomObject]$State) - if (($true -eq $State.Controls.chkInjectUnattend.IsChecked) -and ($true -eq $State.Controls.rbDeviceNamingPrefixes.IsChecked)) { + if (($true -eq $State.Controls.chkInjectUnattend.IsChecked) -and (($true -eq $State.Controls.rbDeviceNamingPrompt.IsChecked) -or ($true -eq $State.Controls.rbDeviceNamingPrefixes.IsChecked))) { $State.Controls.rbDeviceNamingNone.IsChecked = $true } $selectedDeviceNamingMode = Get-SelectedDeviceNamingMode -State $State $State.Controls.deviceNameTemplatePanel.Visibility = if ($selectedDeviceNamingMode -eq 'Template') { 'Visible' } else { 'Collapsed' } $State.Controls.deviceNamePrefixesPanel.Visibility = if ($selectedDeviceNamingMode -eq 'Prefixes') { 'Visible' } else { 'Collapsed' } + $State.Controls.rbDeviceNamingPrompt.IsEnabled = -not ($true -eq $State.Controls.chkInjectUnattend.IsChecked) $State.Controls.rbDeviceNamingPrefixes.IsEnabled = -not ($true -eq $State.Controls.chkInjectUnattend.IsChecked) if ($selectedDeviceNamingMode -eq 'Prefixes') { @@ -435,6 +442,11 @@ function Register-EventHandlers { $window = [System.Windows.Window]::GetWindow($eventSource) Update-DeviceNamingControls -State $window.Tag }) + $State.Controls.rbDeviceNamingPrompt.Add_Checked({ + param($eventSource, $routedEventArgs) + $window = [System.Windows.Window]::GetWindow($eventSource) + Update-DeviceNamingControls -State $window.Tag + }) $State.Controls.rbDeviceNamingTemplate.Add_Checked({ param($eventSource, $routedEventArgs) $window = [System.Windows.Window]::GetWindow($eventSource) diff --git a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Initialize.psm1 b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Initialize.psm1 index e84e1f5..62cac40 100644 --- a/FFUDevelopment/FFUUI.Core/FFUUI.Core.Initialize.psm1 +++ b/FFUDevelopment/FFUUI.Core/FFUUI.Core.Initialize.psm1 @@ -221,6 +221,7 @@ function Initialize-UIControls { $State.Controls.chkCreateDeploymentMedia = $window.FindName('chkCreateDeploymentMedia') $State.Controls.chkInjectUnattend = $window.FindName('chkInjectUnattend') $State.Controls.rbDeviceNamingNone = $window.FindName('rbDeviceNamingNone') + $State.Controls.rbDeviceNamingPrompt = $window.FindName('rbDeviceNamingPrompt') $State.Controls.rbDeviceNamingTemplate = $window.FindName('rbDeviceNamingTemplate') $State.Controls.rbDeviceNamingPrefixes = $window.FindName('rbDeviceNamingPrefixes') $State.Controls.deviceNameTemplatePanel = $window.FindName('deviceNameTemplatePanel') diff --git a/docs/build.md b/docs/build.md index abaad01..3c5849a 100644 --- a/docs/build.md +++ b/docs/build.md @@ -363,6 +363,17 @@ Use the **Device Naming** expander to decide whether `ComputerName` should be se This is the default option. The unattend file is still applied, but Windows generates a random computer name instead of forcing a prompt or a fixed name. +The active `unattend_*.xml` files in `FFUDevelopment\Unattend` use `*` for this default behavior. + +### Prompt for Device Name + +Use this option when you want the technician to enter the computer name during deployment. + +- This option requires **Copy Unattend.xml**. +- The source `unattend_*.xml` files can stay at `*`. +- During the build, FFU Builder rewrites only the staged deployment copy of `Unattend.xml` to the legacy prompt placeholder that `ApplyFFU.ps1` already recognizes. +- **Inject Unattend.xml** is not supported with this option. + ### Specify Device Name Use this option when you want a static device name or a template such as `Comp-%serial%`. @@ -399,9 +410,9 @@ Use **Prefixes File Path** to point the UI at the source text file for the prefi Use **Save Prefixes** to write the current multiline prefixes list back to the file specified in **Prefixes File Path**. -### Legacy Prompt Behavior +### Deployment Prompt Compatibility -Older deployment media that still has an unattend file with `ComputerName` set to the legacy placeholder value and no `prefixes.txt` file will still prompt for a device name during deployment. +Older deployment media that already has an unattend file with `ComputerName` set to the legacy placeholder value and no `prefixes.txt` file will still prompt for a device name during deployment. {: .warning-title} diff --git a/docs/parameters_reference.md b/docs/parameters_reference.md index 67912f0..661c20b 100644 --- a/docs/parameters_reference.md +++ b/docs/parameters_reference.md @@ -41,7 +41,7 @@ This table lists all top-level parameters in BuildFFUVM.ps1. | -CopyUnattend | bool | Copy Unattend.xml | When set to $true, will copy the $FFUDevelopmentPath\Unattend folder to the Deployment partition of the USB drive. Cannot be used together with -InjectUnattend. Default is $false. | | -CreateDeploymentMedia | bool | Create Deployment Media | When set to $true, this will create WinPE deployment media for use when deploying to a physical device. | | -CustomFFUNameTemplate | string | Custom FFU Name Template | Sets a custom FFU output name with placeholders. Allowed placeholders are: {WindowsRelease}, {WindowsVersion}, {SKU}, {BuildDate}, {yyyy}, {MM}, {dd}, {H}, {hh}, {mm}, {tt}. | -| -DeviceNamingMode | string | Device Naming expander | Controls how device naming is handled when unattend content is copied to USB media or injected into the FFU. Accepted values are Legacy, None, Template, and Prefixes. The UI uses None, Template, and Prefixes. | +| -DeviceNamingMode | string | Device Naming expander | Controls how device naming is handled when unattend content is copied to USB media or injected into the FFU. Accepted values are Legacy, None, Prompt, Template, and Prefixes. The UI uses None, Prompt, Template, and Prefixes. Prompt rewrites the staged deployment unattend to the existing manual prompt placeholder and requires -CopyUnattend. | | -DeviceNameTemplate | string | Specify Device Name | Sets the device name used when DeviceNamingMode is Template. Supports a static name or the %serial% token when -CopyUnattend is used. | | -DeviceNamePrefixesPath | string | Prefixes File Path | Path to the source prefixes file used for legacy copy or when -DeviceNamePrefixes is not supplied. Default is $FFUDevelopmentPath\Unattend\prefixes.txt. | | -DeviceNamePrefixes | string[] | Specify a list of Prefixes | Sets the prefixes used when DeviceNamingMode is Prefixes. Each entry becomes a line in prefixes.txt on the deployment media. | diff --git a/docs/quickstart.md b/docs/quickstart.md index 5bd292d..8ed8fe7 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -286,18 +286,22 @@ And the Unattend folder should have an unattend.xml file with the following cont - MyComputer + * ``` +Keep `*` if you want Windows to generate a random device name by default. + +If you want the technician to be prompted for the device name during deployment, select **Prompt for Device Name** in the Build tab and enable **Copy Unattend.xml**. FFU Builder will rewrite only the staged deployment copy of `Unattend.xml` for that workflow. + Now you're ready to deploy the FFU to your device. ## Deployment -Deployment should be fairly straight forward: boot off the USB device, get prompted for a device name, and the deployment of the FFU and drivers should happen automatically. +Deployment should be fairly straight forward: boot off the USB device and the deployment of the FFU and drivers should happen automatically. If you selected **Prompt for Device Name** or another supported device naming option, that naming step will happen during deployment. If you have any questions or run into any issues, [open a discussion in the Github repo](https://github.com/rbalsleyMSFT/FFU/discussions).