Replace SerialNumber with UniqueId for USB drive identification

Switches USB drive matching logic from relying on SerialNumber to using UniqueId, which provides more reliable and consistent device identification across different systems.

Updates the Get-USBDrive function to retrieve UniqueId via Get-Disk and trims the machine name suffix (characters after colon) for consistent matching. The new approach first filters candidates by model and media type, then validates each candidate against the configured UniqueId.

Reflects this change across the UI layer by updating column headers, configuration handling, and drive enumeration functions to use UniqueId instead of SerialNumber for saving and loading USB drive selections.
This commit is contained in:
rbalsleyMSFT
2025-11-24 16:46:57 -08:00
parent 18367219c8
commit 417be73b23
5 changed files with 63 additions and 25 deletions
@@ -114,8 +114,9 @@ function Get-UIConfig {
WindowsVersion = $State.Controls.cmbWindowsVersion.SelectedItem
}
# Save selected USB drives using UniqueId for reliable identification
$State.Controls.lstUSBDrives.Items | Where-Object { $_.IsSelected } | ForEach-Object {
$config.USBDriveList[$_.Model] = $_.SerialNumber
$config.USBDriveList[$_.Model] = $_.UniqueId
}
# Additional FFU file selections
@@ -669,8 +670,9 @@ function Update-UIFromConfig {
}
}
if ($propertyExists -and ($propertyValue -eq $item.SerialNumber)) {
WriteLog "LoadConfig: Selecting USB Drive Model '$($item.Model)' with Serial '$($item.SerialNumber)'."
# Match USB drives by UniqueId instead of SerialNumber
if ($propertyExists -and ($propertyValue -eq $item.UniqueId)) {
WriteLog "LoadConfig: Selecting USB Drive Model '$($item.Model)' with UniqueId '$($item.UniqueId)'."
$item.IsSelected = $true
}
else {