question

PeteMonger-3775 avatar image
0 Votes"
PeteMonger-3775 asked PeteMonger-3775 commented

How to add a virtual USB Drive to a Hyper-V VM

I have a Win 10 Hyper-V VM running and I want to simulate plugging in a virtual USB Memory Stick so that it appears in the VM as a drive letter in Windows Explorer.
The virtual USB Memory Stick is a vhdx file.

I could do this using Mount-DiskImage on the VM, but I want to do it from the Host (where the vhdx file is).

Put another way, how can I use Add-VMHardDiskDrive from the host, while the VM is running?

I want to do this using PowerShell, and I'm running Server 2019 Standard and the VM is Generation 1

windows-server-powershellwindows-server-hyper-v
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

XiaoweiHe-MSFT avatar image
0 Votes"
XiaoweiHe-MSFT answered PeteMonger-3775 commented

Hi,

On the hyper V host, we may use powershell command to mount the VHD to the hyper V host: Mount-VHD -Path C:\Anne\mount.vhdx

34236-image.png

Then, offline the disk on the host disk manager, and not initialize the disk.

Use the powershell command on hyper V host to add the disk to the VM: Get-VMScsiController -VMName hxw-node1 | Add-VMHardDiskDrive -DiskNumber 2

34253-image.png

https://docs.microsoft.com/en-us/powershell/module/hyper-v/mount-vhd?view=win10-ps

https://docs.microsoft.com/en-us/powershell/module/hyper-v/add-vmharddiskdrive?view=win10-ps

Thanks for your time!
Best Regards,
Anne


If the Answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



image.png (50.0 KiB)
image.png (7.1 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks Anne, that's brilliant

0 Votes 0 ·
DSPatrick avatar image
0 Votes"
DSPatrick answered PeteMonger-3775 commented

Some options are outlined here.
https://www.altaro.com/hyper-v/hyper-v-usb/


--please don't forget to Accept as answer if the reply is helpful--




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the reply, but I think that is talking about physical USB sticks, not virtual ones

0 Votes 0 ·