Fix NotSupportedException: Resolve multiple drive letter assignments and mount delays#466
Open
hayashibob wants to merge 1 commit intojamesstringer90:mainfrom
Open
Fix NotSupportedException: Resolve multiple drive letter assignments and mount delays#466hayashibob wants to merge 1 commit intojamesstringer90:mainfrom
hayashibob wants to merge 1 commit intojamesstringer90:mainfrom
Conversation
…and mount delays ### Describe the bug When running `Update-VMGpuPartitionDriver.ps1` on modern Windows 11 environments with `automount` enabled, mounting the VM's VHDX often assigns drive letters to multiple partitions simultaneously (such as the OS partition and the Recovery partition). Because the original code uses `ForEach-Object DriveLetter`, `$DriveLetter` receives an array (e.g., `"E", "F"`). When appending `:`, PowerShell concatenates the array with spaces, resulting in an invalid path format like `"E F:\windows\system32"`. This causes `Copy-Item` to crash completely with a `NotSupportedException`. Additionally, there is a timing issue where the script might execute before Windows fully recognizes the file system, or the disk remains `Offline` depending on the SAN policy, causing the variable to be empty. ### Proposed Solution I rewrote the mount and drive letter acquisition block to be foolproof: 1. Added a 3-second `Start-Sleep` immediately after `Mount-VHD` to allow the file system to initialize. 2. Added a check to force the disk `Online` if it mounts as offline. 3. Used `Sort-Object Size -Descending | Select-Object -First 1` to strictly pinpoint the primary OS partition, ignoring small recovery partitions. 4. If no drive letter is automatically assigned to the OS partition, it forces an assignment and retrieves it. 5. Ensured `$DriveLetter` is exactly one valid drive letter. I have tested this patch extensively on my local Hyper-V environment (Win 11, RTX 4060 Ti) and it successfully transferred all driver files without any path formatting errors. I hope this helps others facing the same issue!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the bug
When running
Update-VMGpuPartitionDriver.ps1on modern Windows 11 environments withautomountenabled, mounting the VM's VHDX often assigns drive letters to multiple partitions simultaneously (such as the OS partition and the Recovery partition).Because the original code uses
ForEach-Object DriveLetter,$DriveLetterreceives an array (e.g.,"E", "F"). When appending:, PowerShell concatenates the array with spaces, resulting in an invalid path format like"E F:\windows\system32". This causesCopy-Itemto crash completely with aNotSupportedException.Additionally, there is a timing issue where the script might execute before Windows fully recognizes the file system, or the disk remains
Offlinedepending on the SAN policy, causing the variable to be empty.Proposed Solution
I rewrote the mount and drive letter acquisition block to be foolproof:
Start-Sleepimmediately afterMount-VHDto allow the file system to initialize.Onlineif it mounts as offline.Sort-Object Size -Descending | Select-Object -First 1to strictly pinpoint the primary OS partition, ignoring small recovery partitions.$DriveLetteris exactly one valid drive letter.I have tested this patch extensively on my local Hyper-V environment (Win 11, RTX 4060 Ti) and it successfully transferred all driver files without any path formatting errors. I hope this helps others facing the same issue!