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
@@ -655,14 +655,14 @@ function Initialize-DynamicUIElements {
$modelColumn.Header = $modelHeader
}
# Serial Number Column (index 1 in XAML, now 2)
# Unique ID Column (index 1 in XAML, now 2)
if ($usbDrivesGridView.Columns.Count -gt 2) {
$serialColumn = $usbDrivesGridView.Columns[2]
$serialHeader = New-Object System.Windows.Controls.GridViewColumnHeader
$serialHeader.Content = "Serial Number"
$serialHeader.Tag = "SerialNumber" # Property to sort by
$serialHeader.HorizontalContentAlignment = [System.Windows.HorizontalAlignment]::Left
$serialColumn.Header = $serialHeader
$uniqueIdColumn = $usbDrivesGridView.Columns[2]
$uniqueIdHeader = New-Object System.Windows.Controls.GridViewColumnHeader
$uniqueIdHeader.Content = "Unique ID"
$uniqueIdHeader.Tag = "UniqueId" # Property to sort by
$uniqueIdHeader.HorizontalContentAlignment = [System.Windows.HorizontalAlignment]::Left
$uniqueIdColumn.Header = $uniqueIdHeader
}
# Size Column (index 2 in XAML, now 3)