-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
enable-msi.ps1
76 lines (65 loc) · 3.31 KB
/
enable-msi.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
[CmdletBinding(PositionalBinding = $true)]
param (
[Parameter(Mandatory, ValueFromRemainingArguments)][string[]]$PCIIDs
)
$ErrorActionPreference = [System.Management.Automation.ActionPreference]::Stop
New-Variable -Option Constant InterruptManagementPath 'Device Parameters\Interrupt Management'
New-Variable -Option Constant MSIEnabledValueName 'MSISupported'
New-Variable -Option Constant MSIPropertiesPath 'MessageSignaledInterruptProperties'
New-Variable -Option Constant RootPath 'HKLM:\SYSTEM\CurrentControlSet\Enum\PCI'
class Device {
[string]$ProductID
[string]$VendorID
Device([string]$vendorId, [string]$productId) {
$this.ProductID = $productId.ToUpper()
$this.VendorID = $vendorId.ToUpper()
}
}
$devices = [System.Collections.Generic.HashSet[Device]]::new()
########################################################################################################################
# process parameters
########################################################################################################################
$PCIIDs.ForEach({
if (-not ($_ -match '^(?<vid>[0-9a-f]{4}):(?<pid>[0-9a-f]{4})$')) {
Write-Error ("PCI ID '$_' is invalid; please use syntax <vendor-id>:<product-id>.")
Exit 1
}
$devices.Add([Device]::new($Matches.vid, $Matches.pid)) | Out-Null
})
########################################################################################################################
# process devices
########################################################################################################################
foreach ($device in $devices) {
Write-Output "`nProcessing device $($device.VendorID):$($device.ProductID)."
$deviceInstanceKeys = Get-ChildItem $RootPath -Depth 1 |
Where-Object Name -Match "\\(VEN_$($device.VendorID)&DEV_$($device.ProductID).+\\.+)"
if ($deviceInstanceKeys.Count -eq 0) {
Write-Output '└ No instances found; skipping device.'
continue
}
foreach ($deviceInstanceKey in $deviceInstanceKeys) {
Write-Output "└ Found instance: $($Matches[1])"
try {
$interruptManagementKey = Get-Item "$($deviceInstanceKey.PSPath)\$InterruptManagementPath"
$msiPropertiesKey = $null;
try {
$msiPropertiesKey = Get-Item "$($interruptManagementKey.PSPath)\$MSIPropertiesPath"
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Output " No '$MSIPropertiesPath' key; creating it."
$msiPropertiesKey = New-Item "$($interruptManagementKey.PSPath)\$MSIPropertiesPath"
}
$msiEnabled = 0
try {
$msiEnabled = (Get-ItemProperty $msiPropertiesKey.PSPath $MSIEnabledValueName).$MSIEnabledValueName
} catch [System.Management.Automation.PSArgumentException] {}
if ($msiEnabled -eq 0) {
Write-Output ' MSI is currently disabled; turning it on.'
Set-ItemProperty $msiPropertiesKey.PSPath $MSIEnabledValueName 1
} else {
Write-Output ' MSI is already enabled; skipping instance.'
}
} catch [System.Management.Automation.ItemNotFoundException] {
Write-Output " No '$InterruptManagementPath' key; skipping instance."
}
}
}