Skip to content

Instantly share code, notes, and snippets.

@bjornbouetsmith
Last active March 9, 2024 14:33
Show Gist options
  • Save bjornbouetsmith/c49f846df160266bf94295a3d5e23d1e to your computer and use it in GitHub Desktop.
Save bjornbouetsmith/c49f846df160266bf94295a3d5e23d1e to your computer and use it in GitHub Desktop.
Hyper-V PCIe Passthrough
#Find pci devices:
(Get-PnpDevice).Where{$_.Class -like '*SCSI*'}|Select-Object -Property FriendlyName,InstanceId
FriendlyName InstanceId
------------ ----------
Microsoft iSCSI Initiator ROOT\ISCSIPRT\0000
Microsoft Storage Spaces Controller ROOT\SPACEPORT\0000
Dell PERC H200 Adapter PCI\VEN_1000&DEV_0072&SUBSYS_1F1D1028&REV_03\4&866E9CF&0&0010
Dell 6Gbps SAS HBA PCI\VEN_1000&DEV_0072&SUBSYS_1F1C1028&REV_03\4&37CB7C8E&0&0018
Microsoft VHD Loopback Controller {8E7BD593-6E6C-4C52-86A6-77175494DD8E}\MSVHDHBA\1&3030E83&0&01
#Find the one you want
$device = Get-PnpDevice -FriendlyName "Dell 6Gbps SAS HBA"
$instanceID = $device.InstanceId
#Disable the device, so you can enable it in hyper-V
Disable-PnpDevice -InstanceId $InstanceId -Confirm:$false
#Show devices disabled
Get-VMHostAssignableDevice
InstanceID : PCIP\VEN_1000&DEV_0072&SUBSYS_1F1C1028&REV_03\4&37CB7C8E&0&0018
LocationPath : PCIROOT(40)#PCI(0300)#PCI(0000)
CimSession : CimSession: .
ComputerName : HYPERV1
IsDeleted : False
$locationPath = (Get-VMHostAssignableDevice)|Select-Object -Property LocationPath
$VM = Get-VM "Name OF VM"
Add-VMAssignableDevice -VM $VM -LocationPath $locationPath -Verbose
#Now the device should be assigned directly to the Virtual machine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment