-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHOTAS_Enable_Disable.ps1
61 lines (55 loc) · 2.42 KB
/
HOTAS_Enable_Disable.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
# Get user parameters
param (
[Parameter()]
[ValidateSet("enable", "disable")]
[String]$action
)
$registryPath = "HKLM:\SYSTEM\CurrentControlSet\Control\MediaProperties\PrivateProperties\Joystick\OEM"
#Fetching Device ID's from registry.
$childKeys = Get-ChildItem -Path $registryPath -Recurse |
Where-Object { $_.Property -match "OEMName" -and $_.GetValue("OEMName") -like "*HOTAS Warthog*" }
if ($childKeys) {
Write-Host "Warhog HOTAS found in registry"
foreach ($key in $childKeys) {
$instanceID = $key.PSChildName
# Search for matching PnP HID devices with the same InstanceID
$pnpDevices = Get-PnpDevice |
Where-Object { $_.InstanceID -like "*$instanceID*" -and $_.InstanceID -like "HID*" }
if ($pnpDevices) {
Write-Host "HID Device found"
foreach ($device in $pnpDevices) {
$deviceId = $device.InstanceID
if ($action) {
if ($action -eq "enable") {
Write-Host "Enabling device $deviceId"
Enable-PnpDevice -InstanceId $deviceId -Confirm:$false
} else {
Write-Host "Disabling device $deviceId"
Disable-PnpDevice -InstanceId $deviceId -Confirm:$false
}
} else {
# Get status of the device
switch ($device.Status) {
# If status is 'OK', disable it
'OK' {
Write-Host "Device $deviceId is enabled"
Write-Host "Disabling device $deviceId"
Disable-PnpDevice -InstanceId $deviceId -Confirm:$false
break
}
# If status is 'default', enable it
default {
Write-Host "Device $deviceId is disabled"
Write-Host "Enabling device $deviceId"
Enable-PnpDevice -InstanceId $deviceId -Confirm:$false
}
}
}
}
} else {
Write-Host "No matching HID devices found for $instanceID."
}
}
} else {
Write-Host "No registry keys found with OEMName containing 'HOTAS Warthog'."
}