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

Pete Monger 21 Reputation points
2020-10-21T12:26:08.437+00:00

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

Hyper-V
Hyper-V
A Windows technology providing a hypervisor-based virtualization solution enabling customers to consolidate workloads onto a single server.
2,813 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,625 questions
0 comments No comments
{count} votes

Accepted answer
  1. Xiaowei He 9,926 Reputation points
    2020-10-22T07:47:34.203+00:00

    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://learn.microsoft.com/en-us/powershell/module/hyper-v/mount-vhd?view=win10-ps

    https://learn.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.


1 additional answer

Sort by: Most helpful
  1. Anonymous
    2020-10-21T12:49:59.213+00:00

    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--


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.